Thursday 15 July 2010

perl - Missing error for undefined value as hash reference -



perl - Missing error for undefined value as hash reference -

i have these 2 snippets of code seemingly should produce same result, latter results in error.

1:

my $href = undef; @values = values %{ $href }; # ok - @values empty

2:

my $href = undef; %hash = %{ $href }; # <-- error here @values = values %hash; # error: can't utilize undefined value hash reference

why having values in same line allow work? i'd rather them both throw error, since using undefined value hash reference mistake. don't have more recent versions of perl test on, reproducible in 5.8.8 , 5.10.1.

values function , accepts hash, array or generic look argument (as stated here) . if pass undef argument "values", detects empty , returns no value. on other hand, if seek explicitly convert undef hash, fail, because it's missing key-value pair.

edit: precise. error happens "strict" directive (which should use, anyway).

perl

No comments:

Post a Comment