Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: How do you find keys of a Blessed Hash?

by james2vegas (Chaplain)
on Oct 08, 2012 at 04:26 UTC ( #997735=note: print w/ replies, xml ) Need Help??


in reply to Re^3: How do you find keys of a Blessed Hash?
in thread How do you find keys of a Blessed Hash?

It's sad that these new features we're getting never work as well as intended (given's lexical $_, the mess of smartmatch, auto-dereferencing with keys and others, treating arrays like hashes).


Comment on Re^4: How do you find keys of a Blessed Hash?
Re^5: How do you find keys of a Blessed Hash?
by moritz (Cardinal) on Oct 08, 2012 at 05:44 UTC
      Sure, those work fine, but aren't really new work, just syntactic sugar over $x = defined($x) ? $x : $value, a local $\ = "\n" (and print), and a function closed over a variable declared in an outer lexical scope (this is actually superior to the sugar, since you can have multiple functions sharing the same variable).
Re^5: How do you find keys of a Blessed Hash?
by tobyink (Abbot) on Oct 08, 2012 at 13:06 UTC

    keys $blessed doesn't work for a very good reason. keys can (in recent versions of Perl) be used with either arrays or hashes. A blessed object can (thanks to overload) be simultaneously dereferencable as a hash and and array. So for blessed objects, you need to manually dereference.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997735]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-07-31 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (255 votes), past polls