Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Not Matching String is Matching

by cchampion (Curate)
on Aug 16, 2003 at 15:20 UTC ( #284337=note: print w/replies, xml ) Need Help??

in reply to Not Matching String is Matching

Mr. Muskrat has found the immediate solution. For your next attempt, let me suggest some improvement in your code, so that it becomes more readable and easier to maintain.

my @ips = (qw( )); my $ignore = join "|", @ips; while (<FILE>){ print unless /$ignore/; } # ----------------------- sub ignore { my $ip = shift; for (@ips) { return 1 if $ip =~ $_ } return 0; } while (<FILE>) { print unless ignore($_) }

The first method creates a regular expression from an array. You can add to an array (or delete) much easier than editing such a complicated regex.

The second example uses a subroutine that, depending on the number of your IPs to ignore, can be much quicker than a regex with alternation.


Replies are listed 'Best First'.
Re: Re: Not Matching String is Matching
by PodMaster (Abbot) on Aug 17, 2003 at 09:02 UTC
    Read `perldoc -f quotemeta', it's kind of important (especially since . matches any character -- I am aware that the incoming ip may be a valid ip or whatnot, but the lesson here is that you're dealing with patterns, intentionally or not).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://284337]
[LanX]: do you like it better now?
[choroba]: Well, getting used to it
[LanX]: several people told me they like saigon. ..
[choroba]: well, beer is good here, surprisingly
[choroba]: also, I discovered several vegan/vegetarian restaurants, so I can avoid meat
[LanX]: ha ha ... happy Czech :)
[choroba]: been to the War Remnants Museum, too. Quite a brutal experience
[choroba]: but still, small-talk about smuggling guns and how Trump is great with US expats isn't my cup of tea
[LanX]: brutal beer?

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-02-26 04:35 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (371 votes). Check out past polls.