Hi Monkees,
I like using global vars when they are genuinely global, but I often end up with unintended global vars, and they bug me.
I was wondering what tricks you use to avoid them or, alternatively, how I might cure my anal retentiveness...
For example, how would I avoid the global $vrx in the following simplified example(yet still allow a persistent value)?
use strict; my $vrx; while(<DATA>){ $vrx = $1 if /^10*(\d*)/; print $vrx . $1 . "\n" if /^20*(.*)/; } __DATA__ 1000100 2001foo 2002bar 300badline 2003hello 1000200 2001bish 2002bash
Tom Melly, pm (at) cursingmaggot (stop) co (stop) ukmap{$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
In reply to Avoiding Global Vars by Melly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |