SPUG: ifs and whiles and hashes...
Ryan Forsythe
ryan2 at webrocket.net
Wed Aug 18 17:34:05 CDT 1999
hi, it's ryan the perl newbie again, with another (probably) simple
question...
i'm writing a program which opens a text file, searches each line, and
extracts data from it and sticks it in a hash...well, that's what it's
supposed to do. here's a simplification of the loop i'm having problems
with:
while (defined($dbaseLine = <DATABASE>)) {
#code here...
if ($dbaseLine =~ m/^\"(?:.*)\",\"(.*)\",\"(.*)\"/) {
$hash{'key1'} = $1;
$hash{'key2'} = $2;
#etc...
} else {
next;
}
}
however, my program has 26 of these '\"(.*)\",' in the 'if
($dbaseLine...' test. when i run it, it assigns the $dbaseLine variable
okay, but when it gets to that if test, it locks up and i watch perl's
cpu time go up to 99%. i'm assuming it's getting in an infinite loop,
but why? i don't understand how an if can cause and infinite loop,
especially when it doesn't affect the test variable of the while it's
wrapped in (if that makes any sense to anybody :))
btw, is there any shorter way to write that 'if' that still stores
substrings?
--ryan
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list