Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] Perl Question


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