| re: Multiple if statements in single while loop--HELP
while (<FILE>)
{
my ($dow, $month, $day, $time, $year, $duration, $clientip, $size, $path, $type, $uid) = split(/\s+/);
my $date = "$dow,$month,$day,$time,$year";
my %uid_uaccount = (
hemmi => 14222,
Jonathan=> 28890,
olav => 33221);
#instead of having a gazillion if statements you just go through the hash:
while (($cuid, $accountno) = each %uid_accountno)
{
# if this part of the hash is what youre looking for, make $account
# the value of this element. And then quit iterating this hash.
if ($cuid == $uid) {$account = $accountno; last;}
}
if ($type eq "o") {$method = RETR;}
if($type eq "i") {$method = STOR;}
unless ($size eq "-" || $duration eq "-")
{
$sth->execute($date,$clientip,$duration,$size,$method,$ uid,$path,$account) or die "Couldn't execute statement: " . $sth->errstr;
}
}
[/code][/quote]
# now each extra user only requires you to add one element to %uid_uaccount.
|