Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Shorten script

by roju (Friar)
on Jul 22, 2003 at 14:45 UTC ( [id://276872]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Shorten script

Roll the inner three checks into a loop. So you have
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 14:56 UTC
    That dosen't do the same thing as the original code did. It would only use the first matching pattern and then stop, and it also had an action for when none of them matched.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://276872]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.