Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: (nearly) readonly globals

by haoess (Curate)
on Jan 19, 2009 at 20:32 UTC ( #737395=note: print w/ replies, xml ) Need Help??


in reply to Re: (nearly) readonly globals
in thread (nearly) readonly globals

Using local creates a temporary instance of the named variable, and you can do what you like with it.

But this does not apply to all special globals, i.e.:

% perl -e 'local $1 = 1' Modification of a read-only value attempted at -e line 1. % perl -e 'local $^S = 1' Modification of a read-only value attempted at -e line 1.

-- Frank


Comment on Re^2: (nearly) readonly globals
Download Code
Re^3: (nearly) readonly globals
by Corion (Pope) on Jan 19, 2009 at 20:35 UTC

      I don't give up:

      % bleadperl -Mstrict -wE 'for $1 ( 10..13 ) { say $1 }' 10 11 12 13

      And now, these globals loose their magic:

      % bleadperl -Mstrict -wE 'for $1 ( 10..13 ) { $1 =~ /^(\d)/; say $1 }' 10 11 12 13

      -- Frank

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-08-21 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (144 votes), past polls