Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Is this BEGIN construct supposed to work?

by JavaFan (Canon)
on Nov 02, 2011 at 22:21 UTC ( #935510=note: print w/ replies, xml ) Need Help??


in reply to Is this BEGIN construct supposed to work?

What makes you think the BEGIN treats %hash as if it were a file-scoped global? Try moving the my %hash; *after* the begin block.

Note also that your claim the keys are retained doesn't seem to be true:

use strict; use warnings; use 5.010; sub routine { my %hash; BEGIN { $hash{KEY} = "string"; } $hash{FOO} = "something else"; say join " ", keys %hash; } routine; routine; routine; __END__ Variable "%hash" will not stay shared at /tmp/hh line 12. KEY FOO FOO FOO


Comment on Re: Is this BEGIN construct supposed to work?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (17)
As of 2015-07-06 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (75 votes), past polls