in reply to exists puzzle
[Code entered this way in the debugger won't give the warning the others mentioned.]c:\perl\perl>perl -de 0 Loading DB routines from perl5db.pl version 1.19 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(-e:1): 0 DB<1> use strict DB<2> use warnings DB<3> our %hash = { 'key1' => 'val1', 'key2' => 'val2' }; DB<4> x \%hash 0 HASH(0x1cbd91c) 'HASH(0x1ca1f4c)' => undef
Note here that %hash has a stringified hash as the key in it (and that key has no value). Since {...} returns a hashref here, and %hash = ... is expecting key/value pairs (or something else that looks like a hash), it grabs the hashref as the first key, stringifies it, and takes undef as the corresponding value.
Compare that to this:
which is probably what you wanted.DB<5> %hash = ( 'key1' => 'val1', 'key2' => 'val2' ); DB<6> x \%hash 0 HASH(0x1cbd91c) 'key1' => 'val1' 'key2' => 'val2' DB<7>
For grins, try this:
That's what a hashref looks like, stringified. Not terribly useful, but a recent Quiz of the Week might be an interesting detour.print {"key"=>"value"}, "\n";
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|