SPUG: ifs and whiles and hashes...
Andrew Sweger
andy at n2h2.com
Wed Aug 18 18:31:17 CDT 1999
On 08/18/99 @ 15:34, the infamous Ryan Forsythe wrote:
:} while (defined($dbaseLine = <DATABASE>)) {
:} if ($dbaseLine =~ m/^\"(?:.*)\",\"(.*)\",\"(.*)\"/) {
:}
:} $hash{'key1'} = $1;
:} $hash{'key2'} = $2;
:} #etc...
:} }
:} }
Some of this can be simplified (by taking advantage of $_) to:
while (<DATABASE) {
($hash{'key1'},$hash{'key2'},...) =
m/^\"(?:.*)............./;
}
But if they keys in the hash remain static throughout the loop, each will
simply get written over. Not sure what you're trying to do there. Perhaps:
while (<DATABASE) {
if (m/^\"(?:.*)............./) {
$hash{$1}{'key2'} = $2;
$hash{$1}{'key3'} = $3; # and so on
}
}
where $1 is selected as some key value from each line of input.
It might not be an infinite loop. Maybe just a horrendous regex that takes
a long time. It's not unusual for a single process on an idle box to hit
99% CPU when it's got a lot of work to do.
What's that module that handles spliting input with quoted elements?
--
Andrew Sweger <andy at n2h2.com> | N2H2, Incorporated
v=206.336.2947 f=206.336.1541 | 900 Fourth Avenue, Suite 3400
"Intelligent Technologies For | Seattle WA 98164-1059
a Safe and Productive Internet" | http://www.n2h2.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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