6

I need to pipe the result of "cat variousFiles" to a perl6 program while requiring the program to take different command line arguments. Perl6 seems to want to take the first argument as a file to be read. I can re-write my routines, but I want to use a pipe from shell. Is there a way to do it?

Here is my program named 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

lisprogtor
  • 5,677
  • 11
  • 17

1 Answers1

5

The lines function is a shortcut for $*ARGFILES.lines.
$*ARGFILES is a magic file handle that represents a concatenation of the files specified as command-line arguments (@*ARGS), and falls back to stdin only if @*ARGS is 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 don't want to be interpreted as filenames, and then use lines().

smls
  • 5,738
  • 24
  • 29
  • 1
    I see ! Thank you smls !!! $*ARGFILES is something new I learned from you today. Thank you bery much !! Always something new to learn everyday (even if I am not in the tech/IT field). – lisprogtor Dec 22 '16 at 06:42