printsuse Data::Dumper; use strict; use warnings; simple_call( animal => 'monkey', fish => 'tuna', insect => 'ant', insect => 'spider' ); ########################## sub simple_call { my %params; while(my($key, $value) = splice @_, 0, 2) { if (exists $params{$key}){ if (ref $params{$key} eq "ARRAY"){ push @{$params{$key}},$value; }else{ $params{$key} = [$params{$key},$value]; } }else{ $params{$key} = $value; } } print Dumper \%params; }
Update:Corrected attribution to saintmike, and deleted unnecessary @params declaration.$VAR1 = { 'insect' => [ 'ant', 'spider' ], 'animal' => 'monkey', 'fish' => 'tuna' };
"Man cannot live by bread alone...
He'd better have some goat cheese and wine to go with it!"
In reply to Re: How to process named parameters that have the same key name?
by NetWallah
in thread How to process named parameters that have the same key name?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |