Perl standard input with argument inside Bash

Posted by neversaint on Stack Overflow See other posts from Stack Overflow or by neversaint
Published on 2010-04-12T08:16:20Z Indexed on 2010/04/12 8:23 UTC
Read the original article Hit count: 204

Filed under:
|
|
|
|

I want to have such pipe in bash

#! /usr/bin/bash
cut -f1,2 file1.txt | myperl.pl foo | sort -u 

Now in myperl.pl it has content like this

my $argv = $ARG[0] || "foo";

while (<>) {
 chomp;
 if ($argv eq "foo") {
  # do something with $_
 }
 else {
   # do another
 }
}

But why the Perl script can't recognize the parameter passed through bash? Namely the code break with this message:

Can't open foo: No such file or directory at myperl.pl line 15.

What the right way to do it so that my Perl script can receive standard input and parameter at the same time?

© Stack Overflow or respective owner

Related posts about bash

Related posts about perl