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

the MAIN questions

Thread Next
From:
Marc Chantreux
Date:
December 29, 2021 12:00
Subject:
the MAIN questions
Message ID:
YcxN5pHGxbtp05xo@prometheus.u-strasbg.fr
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
like

Usage:
  fixlines [--test] <files>

to do so, my

say fixline $_ for lines;

becomes

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
    ) {
    +@files or @files = ('-');
    my $argfiles = IO::ArgFiles.new(@files);
    .&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 = IO::ArgFiles.new(@files);
    .&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 Raku.land?

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