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

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

by Corion (Pope)
on Oct 07, 2012 at 15:06 UTC ( #997687=note: print w/replies, xml ) Need Help??

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

Instead of running off, again, on a wild goose chase, it maybe would be simpler to just read keys, the official documentation? It mentions there that:

Starting with Perl 5.14, keys can take a scalar EXPR, which must contain a reference to an unblessed hash or array. The argument will be dereferenced automatically. This aspect of keys is considered highly experimental. The exact behaviour may change in a future version of Perl.

... and without seeing your code, my guess is that you are "using" that experimental feature, knowingly or not.

  • Comment on Re^3: How do you find keys of a Blessed Hash?

Replies are listed 'Best First'.
Re^4: How do you find keys of a Blessed Hash?
by james2vegas (Chaplain) on Oct 08, 2012 at 04:26 UTC
    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).

      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'
        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).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2018-03-20 03:13 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (247 votes). Check out past polls.