TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:21227] Newbie perl question
Jim Crumley said:
> On Tue, Sep 12, 2000 at 02:13:28PM -0500, Nick.T.Reinking@supervalu.com wrote:
> > for (my $i = 0; $i <= $#addrlist; $i++)
> > {
> > if ($addrlist[$i] eq $addr) { splice (@addrlist, $i, 1); }
> > }
>
> Doesn't this break the array subscripts though. You had an array
> of 4 items (0=a 1=b 2=c 3=d), and you pull out the first one (index 0).
> Now you have (0=b 1=c 3=d). You for statement happily goes on to check
> the next index 1, but it has skipped over checking b because the
> indices change.
In the more general case, absolutely. In my situation, though, an address
will never appear in a list more than once. (Unless users go and edit the
list on disk manually...)
> Anyway, I could have sworn I had that problem, so I would run the
> loop in reverse.
Good idea. You never can trust users to behave the way you intend.
--
"Two words: Windows survives." - Craig Mundie, Microsoft senior strategist
"So does syphillis. Good thing we have penicillin." - Matthew Alton
Geek Code 3.1: GCS d- s+: a- C++ UL++$ P+>+++ L+++>++++ E- W--(++) N+ o+
!K w---$ O M- V? PS+ PE Y+ PGP t 5++ X+ R++ tv b+ DI++++ D G e* h+ r++ y+