Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Assignment and use statement in the same BEGIN block

by tobyink (Abbot)
on Jan 31, 2019 at 09:06 UTC ( #1229192=note: print w/replies, xml ) Need Help??


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

A use within a BEGIN is effectively a BEGIN within a BEGIN.

This should work:

perl -wE'BEGIN { $vars{k} = "v1"; require Acme::PERLANCAR::DumpImportA +rgs; import Acme::PERLANCAR::DumpImportArgs %vars }'

Replies are listed 'Best First'.
Re^2: Assignment and use statement in the same BEGIN block
by perlancar (Pilgrim) on Jan 31, 2019 at 12:22 UTC

    Thanks choroba, my friend Discipulus, and tobyink for all the useful explanation.

    Toby's clicks the most to me. And this snippet makes things very clear to me: BEGIN { say 1; BEGIN { say 2 } } printing 2 before 1. In other words, you ain't finish BEGIN'ing until you end (close) it. Sigh. And the specialness of the use statement again standing in my way.

      > you ain't finish BEGIN'ing until you end (close) it

      (this is life..)

      indeed! and I never realized they can be nested!

      perl -e "$}.=qq(BEGIN{print qq($_);)for(q(,rekcaH lreP rehtonA tsuJ)=~/./g);$}.=q(})x25;eval$}"

      L*

      update

      removed and published separately as obfu

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2019-09-23 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (276 votes). Check out past polls.

    Notices?