Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: How to localize conditionally? (tias)

by tye (Sage)
on Mar 14, 2011 at 15:44 UTC ( [id://893098]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to localize conditionally?
in thread How to localize conditionally?

Did you test it? It works for me.

- tye        

  • Comment on Re^3: How to localize conditionally? (tias)

Replies are listed 'Best First'.
Re^4: How to localize conditionally? (tias)
by ikegami (Patriarch) on Mar 14, 2011 at 16:07 UTC

    No, but how can one assign to a hash element that does not exist? Well, %ENV is magical, so let's test it out.

    $ perl -wE' my $condition = 0; say exists($ENV{BLAH}) || 0; local $ENV{BLAH} = $condition ? 42 : $ENV{BLAH}; say exists($ENV{BLAH}) || 0; ' 0 1

    So I was right

    This is perl 5, version 12, subversion 2 (v5.12.2) built for i686-linu +x

      My tests appeared to work for strange reasons. Sorry about that. But you can fix the original without copying the whole environment:

      local $ENV{BLAH}; if( @ARGV ) { $ENV{BLAH}= 42; } else { delete $ENV{BLAH}; }

      - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-19 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found