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

$*ARGFILES and MAIN

Thread Next
From:
Marc Chantreux
Date:
September 23, 2019 17:59
Subject:
$*ARGFILES and MAIN
Message ID:
20190923175306.GA12383@prometheus.u-strasbg.fr
hello people,

short question: how to use $*ARGFILES in a MAIN function?

context:

as an exercice as well as demo, i reimplement unix filters
(cat, grep, wc, join, paste, ...). Basic wc could be

  multi sub MAIN ( :$l ) { say +lines }
  multi sub MAIN ( :$c ) { say [+] lines>>.chars }
  multi sub MAIN ( :$w ) { say [+] lines.map: +*.words }

now i want grep that can have both -H (head the line with the filename)
and the -n (add the number of the line). my 'almost working' attempt was
but it takes the flags as signatures.

  sub MAIN ( Str $pattern, :$H = False , :$n = False , *@rest ) {
    (IO::ArgFiles.new: @rest).lines>>.say
  }

any help on it?

extra note: i use the perl6 shipped with guix so:

perl6 -v
  This is Rakudo version 2019.03.1 built on MoarVM version 2019.03
  implementing Perl 6.d.

regards
marc

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