develooper Front page | perl.perl6.users | Postings from December 2021

the MAIN questions

Thread Next
Marc Chantreux
December 29, 2021 12:00
the MAIN questions
Message ID:
hello rakoons,

I have a script named fixlines which is basically

sub fixline (Str $line) { ...  }
say fixline $_ for lines;

This is far enough for personal usage but i would like to release it
so i need a decent -h to be implemented and basically should look

  fixlines [--test] <files>

to do so, my

say fixline $_ for lines;


sub MAIN (
    #| don't fix for real, just show the diff
    Bool :$diff = False,
    #| input files (stdin by default or explicit '-' in the list)
    ) {
    +@files or @files = ('-');
    my $argfiles =;
    .&fixline.say for $argfiles.lines

This would be fair enough in any other langages but the whole thing looks
unelegant in a raku code.

So now I have 2 questions:

* I'm pretty sure i saw something like :!$test to express Bool :$test = False.
  Did i just dreamed about it ?
* more importantly, is the a better choice than

    +@files or @files = ('-');
    my $argfiles =;
    .&fixline.say for $argfiles.lines

I saw %*SUB-MAIN-OPTS in the documentation and was wondering if something like

    %*SUB-MAIN-OPTS<ARGFILES>= my @files; #= input files, stdin if none

could be achievable by a module MAIN::UnixFilter i could put on


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About