in reply to Re^2: hash parameter question
in thread hash parameter question
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"; }
|
|---|