Perl6 How to read from stdin and take command line arguments?

I need to pass the result of "cat differentFiles" to the perl6 program, requiring the program to accept different command line arguments. Perl6 seems to take the first argument as a file to read. I can overwrite my routines, but I want to use a pipe from the shell. Is there any way to do this?

Here is my program called testStdInArgs.pl:

say @*ARGS; for lines() { say "reading ==> ", $_; } 

I want to do (foo and bar are arguments):

 cat logFile | perl6 testStdInArgs.pl foo bar 

Here are the errors:

 [foo bar] Earlier failure: (HANDLED) Unable to open file 'foo' in block <unit> at stdInArgs.pl line 2 Final error: Type check failed in binding to $iter; expected Iterator but got Failure (Failure.new(exception...) in block <unit> at stdInArgs.pl line 2 

Thank you very much

+5
source share
1 answer

The lines function is a shortcut to $*ARGFILES.lines .
$*ARGFILES is a magic file descriptor that concatenates files specified as command line arguments ( @*ARGS ) and returns to stdin only if @*ARGS empty.

If you always want to read from stdin, use $*IN.lines :

 for $*IN.lines { say "reading ==> $_"; } 

Alternatively, let your code modify @*ARGS to remove any command line arguments that you do not want to interpret as file names , and then use lines() .

+5
source

Source: https://habr.com/ru/post/1261691/


All Articles