[OT] Perl woes

Jonathan McKeown jonathan+londonpm at hst.org.za
Wed Jan 28 14:58:54 GMT 2009


On Wednesday 28 January 2009 15:24:43 Jonathan Stowe wrote:
> 2009/1/28 Jonathan McKeown <jonathan+londonpm at hst.org.za>:
> > On Wednesday 28 January 2009 14:30:20 Jonathan Kimmitt wrote:
> >> However, what about this one:
> >>
> >> for (my $i==0; $i<($tbl_width - 1); $i++) { .... }
> >>
> >> Is anybody seriously arguing this could possibly do anything useful. Yet
> >> it is not trapped out as an error unless you add the obscure syntax:
> >>
> >> use warnings FATAL => 'all';
> >
> > I think you've got two mistakes here. If you wanted to go round the loop
> > $tbl_width times starting from 0, you needed either
>
> I suspect that the actual problem is the use of the comparison rather
> than assignment in the first clause of the C style for.

Yes, I'd spotted that: that's the first mistake. The second is what appears to 
be an off-by-one in the termination condition (usually if you mention 0 and 
$tbl_width-1 in the same expression it's because you want to start at 0 and 
go round $tbl_width times, which the original code doesn't achieve).

I'm trying to be helpful by pointing out a way to do the loop which makes the 
intention much clearer to the reader and harder to get wrong for the author.

Jonathan


More information about the london.pm mailing list