Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Deparse says \my(%hash) is the same as \my %hash but it isn't (empty)

by tye (Sage)
on Nov 21, 2012 at 17:19 UTC ( #1004965=note: print w/replies, xml ) Need Help??

in reply to Re: Deparse says \my(%hash) is the same as \my %hash but it isn't
in thread Deparse says \my(%hash) is the same as \my %hash but it isn't

In the OPís code, warn appears to be treating \my(%hash) as undef, and not as \undef, as would be expected. I donít see the reason for this, either.

\( ... ) returns a list of references, one reference for each item in the list. my(%hash) initializes %hash to be empty so, %hash in a list context gives the empty list. Constructing a reference to each scalar in an empty list gives one an empty list of references, which is just an empty list. warn treats an empty list the same as a list containing one (or more) undef(s). No mystery there (for me).

As to the original question, it looks to me to just be a bug in Deparse.

Now, I could see Perl deciding to go either way on whether \my(%hash) should be treated like \my %hash or like \(my %hash). My guess is that the current behavior was not a conscious choice but was more an accident of implementation details. So it would be conceivable to fix the Deparse bug by changing Perl to agree on this specific point. But that seems unlikely (surely p5p would argue that there might be code that already depends on the current behavior of \my(%hash), a point that I probably give much less weight to but that I agree with).

I'm not going to dive into the Deparse source code to try to get an idea as to how complicated it might be to fix the deparsing of \my %hash (without breaking the deparsing of some other obscure use of 'my'). But I suggest the original poster report it as a bug in the module.

- tye        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004965]
[choroba]: My recent record is 10km in 1 hour :)
[perldigious]: Nice erix... perldigious' legs are so sore from portaging his kayak from place to place last weekend he can barely hobble 12m. :-)
[erix]: you're faster than me then :)
[erix]: well, at the moment, that is :)
[erix]: I should lose some weight although I keep telling myself that I'm doing extra training by lugging it along
[erix]: I saw a common kingfisher and a couple of bullfinches
[erix]: bullfinch ( a male and a female )
erix learned the word 'portaging' not so long ago (from vikings lugging their ships from one river-system to another)

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-05-24 12:44 GMT
Find Nodes?
    Voting Booth?