Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Assignment and use statement in the same BEGIN block

by choroba (Cardinal)
on Jan 31, 2019 at 07:39 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1229189]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found