- To: Peter Abbott <abbottp_c@xxxxxxxxxxxxxxxx>
- Subject: Re: [SLUG] Perl Question
- From: Rick Welykochy <rick@xxxxxxxxxxxxx>
- Date: Wed, 02 Apr 2008 16:07:10 +1100
- Cc: slug@xxxxxxxxxxx
- User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7
Peter Abbott wrote:
if ( $_ =~ m/^Box(\d) ([A-Z]+(\. | ?)[A-Z]* ?[A-Z]*).*?(\d).*?(\d\d\.\d
\d).*?(\d*\.\d\d)L/) {
$box = $1;
$name = $2;
$place = $4;
$time = $5;
$margin = $6;
$name =~ s/\.//;
}
correcto
However if the $name substitution is inserted above $place like so it
fails to allocate values to $place, $time and $margin.
if ( $_ =~ m/^Box(\d) ([A-Z]+(\. | ?)[A-Z]* ?[A-Z]*).*?(\d).*?(\d\d\.\d
\d).*?(\d*\.\d\d)L/) {
$box = $1;
$name = $2;
$name =~ s/\.//;
$place = $4;
$time = $5;
$margin = $6;
}
incorrecto and hard to maintain
You've also introduced a very subtle bug that I could not, at first
glance, see. The $name substitution resets $1 ... $6.
Please write maintainable code that is easy to understand.
I wouldn't want to be given the second code example buried amongst
1000+ lines of perl and then asked to fix "the obscure bug".
cheers
rickw
--
________________________________________________________________
Rick Welykochy || Praxis Services || Internet Driving Instructor
The best way to accelerate a PC is 9.8 m/s2
-- anon