http://www.perlmonks.org?node_id=987103


in reply to Re^2: Process mail logs
in thread Process mail logs

Certainly. The given/when (or for/when) construct is cleaner, but there's no reason you can't fall back on a series of if/elsif/else. (Though I'd recommend looking at the dispatch table concept first.) In your sample data, the fields appear consistent up to the 'directional' field you're looking at, so you could:

while(<DATA>){ chomp; my( $month, $day, $time, $host, $ppid, $date, $time2, $something, $d +irection, $remainder ) = split ' ', $_, 10; if( $direction eq '<=' ){ # go left } elsif( $direction eq '=>' ){ # go right } elsif( $direction eq '==' ){ # do a third thing } elsif( $direction eq '**' ){ # do a fourth thing } else { # fall back on a default behavior } }

Aaron B.
Available for small or large Perl jobs; see my home node.