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

Re: $*ARGFILES and MAIN

Thread Previous | Thread Next
From:
Brad Gilbert
Date:
September 24, 2019 04:34
Subject:
Re: $*ARGFILES and MAIN
Message ID:
CAD2L-T33i3RFnKafd7R3ULdK9xGz=g+zZ88WMpxdWm18zHWF3Q@mail.gmail.com
You can create your own $*ARGFILES.

    sub MAIN ( +@ARGS ){
      my $*ARGFILES = IO::ArgFiles.new( @ARGS || $*IN );
      .say for lines;
    }

Note that IO::ArgFiles is now only just a subclass of IO::CatHandle.

On Mon, Sep 23, 2019 at 2:51 PM Marc Chantreux <eiro@phear.org> wrote:

> hello,
>
> > >  multi sub MAIN ( :$c ) { say [+] lines>>.chars }
> > Isn't that just `slurp.chars` ?
>
> correct :)
>
> > >  multi sub MAIN ( :$w ) { say [+] lines.map: +*.words }
> > Isn't that just `+words` ?
>
> Aren't you awesome ? At least you're right: the doc says:
>
>   multi sub words
>   ( IO::Handle:D $fh = $*ARGFILES
>   , $limit = Inf
>   , :$close --> Seq:D)
>
> and it work like a charm.
>
> > You should **never** use >>. on anything that you expect the order of
> > execution to be the order of the input.  `>>.` allows the compiler to
> > execute the code over multiple threads, so the `say` could be shown
> > out of order.
>
> wow ... thanks for pointing this. still can't mix MAIN and ARGFILES but
> learned. thank you very much.
>
> regards
> marc
>

Thread Previous | Thread Next


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