I want my perl script to be able to do this:
$ ./code file.txt | myperl.pl param1 param2
So basically it will take input (STIDN) from ./code and execute it with param1 and param2.
But why this doesn’t work:
my $param1 = $ARGV[0];
my $param2 = $ARGV[1];
while (<>) {
if ($param1 > 0.5 && $param2 > 0) {
# do something
}
}
What’s the right construct to do it?
<>akareadline‘s default argument is ARGV, which is a magic filehandle that reads from all the files specified in @ARGV, or from STDIN if there are none. Since you are providing arguments, you either need to clear them out of @ARGV before using<>, or explicitly specify<STDIN>and not use the magic ARGV handle.