Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: negative regex without !~

by arden (Curate)
on Jul 22, 2004 at 15:36 UTC ( [id://376622]=note: print w/replies, xml ) Need Help??


in reply to negative regex without !~

What piece of software are you dealing with that "cannot do negative matches"? I'm going to go out on a limb here and guess it isn't Perl, which leads to my second question: What does this have to do with Perl? Why are you asking at PerlMonks?

Again, if your "special" software doesn't allow for !~ then how are we to guess at if something else will succeed or fail within this "special" software without knowing what that software is?

- - arden.

Replies are listed 'Best First'.
Re^2: negative regex without !~
by grinder (Bishop) on Jul 22, 2004 at 16:55 UTC
    I'm going to go out on a limb here and guess it isn't Perl

    A questionable assumption. Define Perl.

    One likely scenario is software compiled with the PCRE library. A growing number of applications do so these days. I know Apache will use it if it's there (although I don't know what for... maybe mod_rewrite these days?) and so will Postfix (and I'm a heavy user of it and very happy it's available).

    A pure-Perl scenario I can envisage is a callback/library situation, where you get to construct an object or otherwise pass a qr/.../ where the design (admittedly somewhat brain-damaged) only admits positive matches. The not, ! and unless solutions in the other responses does one no good if you can't manoeuvre around the code that's doing the matching.

    So please don't be so hasty in dismissing a person and telling them to go away. I agree the OP should have provided more information, but since it was posted here, maybe it has something to do with Perl?

    - another intruder with the mooring of the heat of the Perl

Re^2: negative regex without !~
by fletcher_the_dog (Friar) on Jul 22, 2004 at 18:58 UTC
    There are many perl CGI and Tk programs that ask a user to enter regular expressions. If you are entering a regular expression in an entry box you typically cannot put '!~' on the front of it to negate it. I don't know if this is the kind of thing the original poster is talking about, but it seems like a very possible scenario
      File::Repl has a function that takes a qr (or a string that will be eval'ed as a regex), for instance. If I want to make a zip of a directory containing all files that are not ending in ".obj" and also do not contain the string "super-secret-gamma-ray-gun", I can't do that with File::Repl and I have to post-match.
Re^2: negative regex without !~
by blueAdept (Beadle) on Jul 22, 2004 at 16:56 UTC
    I'm fairly sure the $foo !~ m/../ syntax didn't exist in perl 5.0, but my impression to the original poster's question is that it really doesn't relate to perl itself of any version. I used to have to write a lot of backwards compatible code, so this was useful knowledge.... but who's still using 5.0 these days <grin>
      Works in 5.005

      but who's still using 5.0 these days?

      <sheepishly> Me. Some companies haven't upgraded.... </sheepishly>

      use strict; print 'Perl version is: ', $]; my @foo = qw/ fee fie fo fum big bag boz /; foreach ( @foo ) { if ( $_ !~ /f/ ) { print "Matched: $_ !~ /f/ " ; } else { print "Failed: $_ !~ /f/ " ; } } Output: Perl version is: 5.00503 Failed: fee !~ /f/ Failed: fie !~ /f/ Failed: fo !~ /f/ Failed: fum !~ /f/ Matched: big !~ /f/ Matched: bag !~ /f/ Matched: boz !~ /f/

      -------------------------------------
      Nothing is too wonderful to be true
      -- Michael Faraday

        Perl version 5.00503 is essentially Perl 5.5.3; they changed the release version numbers starting with Perl 5.6.0

      No, I recall using !~ even back in Perl 4.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://376622]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-18 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found