Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: How come undef eq '' ??

by muba (Priest)
on Jan 31, 2013 at 01:45 UTC ( #1016192=note: print w/replies, xml ) Need Help??


in reply to Re^3: How come undef eq '' ??
in thread How come undef eq '' ??

This code feels... itchy... to me. No offense ;)

Let's assume ref($hash) ne 'HASH', then $data = $hash, so ref($data) will never eq 'HASH', so that statement modifier on the last line is redundant in this case.

However, say ref($hash) eq 'HASH' is true, then $data = $$hash{$name}, and then $data = $$data{CONTENT} provided that $$hash{$name} is a hashref. For the sake of argument, let's say it isn't. Then $data will still be $$hash{$name}. Is that how it's supposed to work?

Replies are listed 'Best First'.
Re^5: How come undef eq '' ??
by tmharish (Friar) on Jan 31, 2013 at 07:05 UTC
    This code feels... itchy... to me. No offense ;)

    None Taken!

    The idea of this bit is to extract the next level of an XML tree ( stored in a hash, in this case $hash )

    So if ref( $hash ) ne 'HASH' then we are at a leaf and $hash is the actual value and not a sub-tree, and hence the $data = $hash ( now they are both scalar )

    On the other hand, if ref($hash) eq 'HASH' then we are dealing with a sub-tree - so $data = $$hash{$name} is fine.

    There is, however, one exception, and that is when '$hash' contains the key 'CONTENT' like so: $$hash{ CONTENT }. In that case $$hash{ CONTENT } is not a sub-tree but a place holder for the actual data and hence the  $data = $$data{CONTENT}

    Of course this requires that CONTENT is never a key in our hash (although it might be a node in the XML) - but that is achieved during parsing of the XML into the hash.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016192]
help
Chatterbox?
[erix]: yeah, I ask for the text (I don't see signatures)
[Discipulus]: dear brother karl has "Furthermore I consider that Donald Trump must be impeached as soon as possible" in his sig
[erix]: ah, thanks Discipulus
[1nickt]: erix perhaps you could kindly point out your technique to roho and everyone will be happy.
[Discipulus]: but i'm also animalist, so i' hirted by 1nickt's sig: The way forward always starts with a mammal test... grin..
[erix]: I might if I did remember. It's probably somewhere in the site docs
[uhClem]: I don't favor that sort of thing around here but the place for our politics is wherever we live.
[uhClem]: And besides, the objection to it was off-topic.
[Discipulus]: 1nickt hide signature is a positive action; i think is not a solution here

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-06-22 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.