print "not ref:\n";
test(dogs=>'bark', cats=>'miaow');
print "ref:\n";
test({dogs=>'bark', cats=>'miaow'});
sub test{
my $params;
ref($_[0]) ? $params = shift : $params = {@_};
print Dumper($params);
}
####
not ref:
$VAR1 = {
'cats' => 'miaow',
'dogs' => 'bark'
};
ref:
Odd number of elements in anonymous hash at params.t line 16.
$VAR1 = {
'HASH(0x81194e0)' => undef
};
####
not ref:
hello
$VAR1 = undef;
ref:
$VAR1 = {
'dogs' => 'bark',
'cats' => 'miaow'
};
####
if(ref($_[0])){
$params = shift;
}
else{
$params = {@_};
}
####
not ref:
$VAR1 = {
'cats' => 'miaow',
'dogs' => 'bark'
};
ref:
$VAR1 = {
'cats' => 'miaow',
'dogs' => 'bark'
};