Wow, lots of very interesting arguments to both sides of the debate, but no-one appears to have made the point that:
my( $foo, $bar ) = @_;
...is not the same as...
my $foo = shift;
my $bar = shift;
The latter approach
modifies the parameter list, they are
gone. In the former case, they stay around to haunt you, especially if someone else calls a &foo, and what's left of @_ gets passed along. Talk about effects at a distance. One alternative is to never call
&foo, but
foo() instead. The other alternative is to use the
shift approach. (note to self: remember to adopt
tye's approach to fetching parameters).
If the routine is small enough I use $_[0] (in which case what $_[0] should contain should be easy to infer from the sub's name). But not everything can be done with $_[0]. If you want to modify it you must fetch the parameter, viz:
sub x {
$_[0] =~ s/foo/bar/;
$_[0];
}
print x('food'), "\n"; # does not work
print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
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.