How can I mix command line arguments and filenames for <> in Perl?

Posted by Jimmeh on Stack Overflow See other posts from Stack Overflow or by Jimmeh
Published on 2010-02-26T21:25:40Z Indexed on 2010/03/16 13:46 UTC
Read the original article Hit count: 173

Filed under:
|
|

Consider the following silly Perl program:

$firstarg = $ARGV[0];

print $firstarg;

$input = <>;

print $input;

I run it from a terminal like:

perl myprog.pl sample_argument

And get this error:

Can't open sample_argument: No such file or directory at myprog.pl line 5.

Any ideas why this is? When it gets to the <> is it trying to read from the (non-existent) file, "sample_argument" or something? And why?

© Stack Overflow or respective owner

Related posts about perl

Related posts about input