Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Avoiding Global Vars

by dsheroh (Monsignor)
on Sep 23, 2009 at 14:03 UTC ( [id://796976]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Avoiding Global Vars
in thread Avoiding Global Vars

One point to clarify is that the reason it bugs me, apart from wanting vars to only live within the scope where they are needed, is that I might re-use the name $vrx later, with possible side-effects.

If you use warnings, you'll get a warning if you redefine a new my $vrx in the same scope as the first. If it's not in the same scope, then it'll be a different $vrx, so there should be little to no chance of unintended side-effects.

Of course, the better way to deal with it would be to use a more meaningful/distinctive name so that it's unlikely that you'll have cause to re-use the name...

Replies are listed 'Best First'.
Re^4: Avoiding Global Vars
by Melly (Chaplain) on Sep 23, 2009 at 15:29 UTC

    Ah, but I might (stupidly) do something like:

    my $urx = 0; # no warning on mistyped $vrx
    print $vrx; # get's old $vrx
    

    As for more meaningful/distinctive, vrx, for reasons relating to the specific tech I'm working with, is very meaningful...

    Thanks again.

    map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
    Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2026-03-08 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.