On Wed, Jan 30, 2002 at 05:48:14PM +0100, [EMAIL PROTECTED] wrote: > Hi all, > > thanks to all in the group who really never stop helping. > This group is really enjoyable. [This had to be said] > > Now. > I'm running a while loop with a hash several times and I want to use the last >statement to exit the loop on a match. > works fine. > > Entering the next time the while loop is exited w/o finding the right match. It >seems the last state on exiting is still preserved and causes the premature exit. >What do I do wrong? > Is there some pointer for the hash I have to reset? > It runs ok w/o the last statement...but I don't want to loop unnecessarily.. > > ---8<---- > if ( $raw[3] eq ""){ > while ( ($key, $value) = each %table ) { > if ($raw[2] =~ /$key/) { > $raw[3] = $value ; > last; > } > } > } > ----8<----
You have a few things that can carry over; it depends on the surrounding code, and what you made lexical. Your biggest problem is probably with %table. A hash has an internal iterator for use by each. The iterator is reset when each is done, or when you call keys on the hash. Given your code, it's likely the iterator is never reset, so each time you hit the loop you're getting new keys, not starting over with the hash. To fix it either call keys(%table) on the hash before the next iteration, or use a lexically scoped hash. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]