You need to understand what the diamond operator does:
- Does the operator have an active filehandle, if not, shift an argument off @ARGV and open it for input as the active filehandle or if @ARGV is empty, set the active filehandle to STDIN.
- If called in list context, return all lines from the active filehandle.
- If called in scalar context and the filehandle is at the end of the file, return undef.
- Otherwise, return a single line from the filehandle.
That's pretty much it. I might be forgetting some subtleties.
The key bit, I've highlighted for you in bold. It uses @ARGV to figure out what file to read, and it alters that array!
So the first time you read a file using the diamond operator, you read it fine. The second time you try to read the file, the filename is no longer on @ARGV, so the diamond operator reads from STDIN instead.
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.