Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Undesirable parent hash keys

by Athanasius (Chancellor)
on Jan 11, 2013 at 07:50 UTC ( #1012817=note: print w/replies, xml ) Need Help??

in reply to Undesirable parent hash keys

You should be testing using exists, because the boolean test you are using will return false if the hash element exists but is undef or zero or the empty string...

That said, I don’t think there is any way to do what you want without the clumsy cascade of tests:

if (exists $Hash{'2013'} && exists $Hash{'2013'}{'Oct'} && ...

because exists also autovivifies intervening elements. According to the documentation:

This surprising autovivification in what does not at first—or even second—glance appear to be an lvalue context may be fixed in a future release.


Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Undesirable parent hash keys
by sophate (Beadle) on Jan 11, 2013 at 07:55 UTC

    Noted and thanks for your prompt response.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012817]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-06-24 08:59 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.