Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Assignment and use statement in the same BEGIN block

by choroba (Bishop)
on Jan 31, 2019 at 07:39 UTC ( #1229189=note: print w/replies, xml ) Need Help??


in reply to Assignment and use statement in the same BEGIN block

Each use statement is executed at the moment it's been parsed. The same applies to a BEGIN block. my has two parts - the declaration of the variable happens immediately at compile time, the assignment happens later at run time. Therefore, in the first case, the dumping happens before the BEGIN block has been fully parsed, which means its (the BEGIN block's) code hasn't been run yet.

To make the variable lexical, specify

my %vars;
before the BEGIN block.

Update: You probably wanted something like

{ my %vars; BEGIN { $vars{k} = 'v'; } use Acme::PERLANCAR::DumpImportArgs %vars; }

Update 2: Explanation of two parts of my.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2019-10-23 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?