in reply to Shorten script
my @patterns = (qr/(patternOne)/, qr/(patternTwo)/); my $match; print "PAGE ->\t$name\ndata ->"; for my $pat (@patterns) { if ($line =~ $pat and not $match++) { print "\t\t$1\nMATCHED - >\t$hit\n"; push (@files, $name); $ct++; last; } } $print " TEXT INFO HERE.\n" if not $match;
Mmmmm refactoring. See also Once and Only Once.
Update: Fixed bugs pointed out by Re: Re: Shorten script. Big error, thanks for the heads-up. Hrm. Could probably still be cleaned up more.. let's call that an exercise to the reader..
Update: stole idea (break up prints) from sauoq's response. If you are unlikely to add more conditions, his way is probably better. Mine is pretty easy to add new conditions to though, just add to the @patterns = (...);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Shorten script
by Anonymous Monk on Jul 22, 2003 at 18:56 UTC |