The Perl print function, which has a long history
and a tricky syntax,
takes an optional file handle as its first argument.
Without the optional first file handle argument, it prints
to the default output handle (typically STDOUT).
Moreover, it has a special syntax where its first
and second arguments
are separated not by a comma (like most Perl functions) but by a space!
And because your first argument to print is more complex
than a plain scalar variable, you need to specify it
in a bare block, for, erm, historical reasons.
Note that this special block syntax to print is clearly documented:
If you're storing handles in an array or hash, or in general whenever
you're using any expression more complex than a bareword handle or a
plain, unsubscripted scalar variable to retrieve it, you will have to
use a block returning the filehandle value instead
However, you then made the (perfectly understandable) "mistake" of
assuming that this special print syntax applies to other Perl
functions, such as close.
When calling most Perl functions, you should not place
the first function argument in a block; this is a one-off
special case for the print function.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
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.
|
|