in reply to Re^2: hash parameter question
in thread hash parameter question

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"; }