develooper Front page | perl.perl6.users | Postings from September 2019

Re: $*ARGFILES and MAIN

Thread Previous
From:
Marc Chantreux
Date:
September 24, 2019 06:17
Subject:
Re: $*ARGFILES and MAIN
Message ID:
20190924061655.GB9945@prometheus.u-strasbg.fr
On Mon, Sep 23, 2019 at 11:34:14PM -0500, Brad Gilbert wrote:
> You can create your own $*ARGFILES.
> 
>     sub MAIN ( +@ARGS ){
>       my $*ARGFILES = IO::ArgFiles.new( @ARGS || $*IN );
>       .say for lines;
>     }

the way i understand https://docs.perl6.org/language/variables, my
dynamic (my $*) variable is the raku way to have a local variable.

i played around it and got:

  sub snitch { say join ',', $*ARGFILES.handles }
  sub MAIN ( $pattern, Bool :$H, Bool :$n, +@files ) {
    my $*ARGFILES = IO::ArgFiles.new(@files);
    snitch;
  }

surprisingly compared to the rest of the code (especially when liz
reviews it!) and when you consider (as i do) that raku will be used to
write tons of filters. but hey! it works :)

thank you very much for help.

marc

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About