homepage Welcome to WebmasterWorld Guest from 54.167.174.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
If Not a Match, do this
Regex question
StaceyJ

5+ Year Member



 
Msg#: 4258646 posted 9:46 pm on Jan 26, 2011 (gmt 0)

I was wondering if it's possible to say something like

If this string DOESN'T match this, do this...like for instance

if !($string =~ m|>.*Widget<|) {
$string =~ s|>(.*)Widg<|>$1Widget<|;
}

That's a rough example, but it gives you the basic idea. I tried it and of course it wasn't very happy with me and gave me an error. Can you not use a negative match like that, or must I have an ELSE to go along with it? I was under the impression an ELSE wasn't required, but the error seemed to suggest otherwise.

 

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4258646 posted 10:32 pm on Jan 26, 2011 (gmt 0)

yeah, it's possible, in two ways:

if(!($string =~ m|>.*Widget<|)) {
   $string =~ s|>(.*)Widg<|>$1Widget<|;
}


which is: if not(string matches foo)

if($string !~ m|>.*Widget<|) {
   $string =~ s|>(.*)Widg<|>$1Widget<|;
}

which is: if string not matches foo

StaceyJ

5+ Year Member



 
Msg#: 4258646 posted 10:56 pm on Jan 26, 2011 (gmt 0)

Ahhhh, thank you! I was so close. I searched and searched and came up with nothing helpful and I like to try to figure things out on my own before asking for help.

Question, jdMorgan has taught me a lot about efficiency with his htaccess regex examples, is one more efficient or a better way than the other?

Thank you again!

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4258646 posted 3:38 pm on Jan 27, 2011 (gmt 0)

I really couldn't say, but I wouldn't be surprised if perl optimized ! =~ to !~. You could benchmark it, but I doubt you'd win much in either case.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved