For extra credit, explain why it doesn't print "23First1Second1" - which would seem to be the most obvious result.
Because the arguments to print are all evaluated first, then printed. ie, it's effectively:
@args = (2,3,first,second);
print @args;
So 'first' and 'second' are run (generating output), before the print command w/ the list is performed.
Similarly, foreach (&func1, &func2) { ... } will run both 'func1' and 'func2' before starting the loop:
foreach ( &func1, &func2 ) { print "Looping : $_"; }
sub func1 { print "func1 called\n"; return "func1 return val\n"; }
sub func2 { print "func2 called\n"; return "func2 return val\n"; }
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.