Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: "eval" and "my" variable weirdness

by ikegami (Patriarch)
on Jun 29, 2006 at 17:23 UTC ( [id://558394]=note: print w/replies, xml ) Need Help??


in reply to Re^3: "eval" and "my" variable weirdness
in thread "eval" and "my" variable weirdness

Of course! You're right, except your version gives a warning. The following removes it:
{ use warnings; my $thingy = 'thangy'; sub doit { 0 && $thingy; # Close over $thingy eval 'print "thingy is $thingy\n"'; } } doit(); # "thingy is thangy"

Replies are listed 'Best First'.
Re^5: "eval" and "my" variable weirdness
by diotalevi (Canon) on Jun 29, 2006 at 17:24 UTC

    Your version is dangerously close to getting optimized away into nothingness. Just disable the warning. That's much safer.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      It *is* optimized away (according to Deparse), but not before satisfying our needs. The safe version would be:

      { use warnings; my $thingy = 'thangy'; sub doit { no warnings 'void'; $thingy; # Close over $thingy eval 'print "thingy is $thingy\n"'; } } doit(); # "thingy is thangy"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found