It seems this should be easy, but I've been banging my head against the wall...
I want to call my perl script with 1 parameter and an output from another script, like this:
perl script1.pl | perl script2.pl 1
Then I want to store the parameter in a variable and parse the piped input, like so:
$num = @ARGV[0];
while (<>)
{
(parser algorithm)
}
print ("$result");
Well, it doesn't work. I get the error "Can't open 1: no such file or directory" and the parsed output is as if no data has been processed. I assume this is because the 1 is going into <> along with the piped input. Is there some way I can get it out of there before going into my while loop?
Also, a curiosity is that the following code behaves slightly differently:
$num = @ARGV[0];
printf (<>);
while (<>)
{
(parser algorithm)
}
print( "$result" )
I still get the error message, but now the parser output is correct. I could just redirect stderr to null and my output is perfect ;) but I'd like to know the "right" way to do this.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.