in reply to Inconsistency of 'Use of uninitialized value in scalar assignment' warning

What rather surprises me is the order of errors.¹

In the first call Perl accepts passing an yet undefined hash value for the key "not_existing". E.g. you may want to populate it in foo!²

In the second call it warns about an undefined key. Keys are strings not undef which must be mapped to "".

Different things.

Cheers Rolf

( addicted to the Perl Programming Language)

update

¹) ah ok, now that I can test it's obvious why! Both warnings are for the second call. The first doesn't cause warnings.

²) demonstration of a legal use case

DB<102> sub populate { $_[0]="xxx" } DB<103> populate $hash{not_existent} => "xxx" DB<104> \%hash => { not_existent => "xxx" } DB<105> use warnings; populate $hash{+ undef} Use of uninitialized value in hash element at ...

Replies are listed 'Best First'.
Re^2: Inconsistency of 'Use of uninitialized value in scalar assignment' warning
by choroba (Cardinal) on Dec 26, 2013 at 11:18 UTC
    Yes. You can experiment with simpler
    foo($hash{ undef() });
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ