Well, chromatic is right, but his answer bothered me anyway. After thinking about it for a bit I believe I put my finger on why. I tend to parse arguments using the
my $arg1 = shift;my $arg2 = shift; idiom. I know, the OP didn't do that, but bear with me.
Parsing the arguments like chromatic did will likely lead to headache if you are passing anything other than scalars. And if your sub has more than 1 argument, there is a good chance you are. Passing arguments as scalar refs just makes my code simpler to think about. That's why I almost always do it that way, and why I gave the advice I did. Examples of headaches and non-DWIM behavior are in code below, which produces errors on both subs:
use strict;
use warnings;
my %nested = ( first => { one => 'two' }, second => { three => 'four'
+} );
pass_the_hash_1(%nested, 'second argument');
pass_the_hash_2(%nested, 'second argument');
sub pass_the_hash_1
{
my %first_argument = shift;
my $second_argment = shift;
print "$first_argument{first}{one} should be two\n";
}
sub pass_the_hash_2
{
my %first_argument = shift;
my $second_argment = shift;
print "$second_argment should be second argument\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.