CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
what is wrong with my if?

 



emelin
stranger

Feb 21, 2001, 7:42 AM

Post #1 of 4 (517 views)
what is wrong with my if? Can't Post

if ((($thing =~ /$FORM::part/ig) and ($thing =~ /SMP/ig)) or (($thing =~ /AI/g) and ($thing =~ /SMP/ig))) {
...do stuff...
}

I'm trying to find something that includes "$FORM::part and SMP" or "AI and SMP"...
This doesn't work... it executes the "else" if there is one, but I KNOW there are matches...

I've tried with || and && as well, not quite sure of the difference... but nothing seems to work! What am I doing wrong?

thankful for help
emelin



muinatit
Deleted

Feb 21, 2001, 12:22 PM

Post #2 of 4 (510 views)
Re: what is wrong with my if? [In reply to] Can't Post

try this...


Code
if (($thing =~ /$FORM::part/ig && $thing =~ /SMP/ig) || ($thing =~ /Al/g && $thing =~ /SMP/ig)) { 
# ...
}

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


emelin
stranger

Feb 22, 2001, 12:32 AM

Post #3 of 4 (503 views)
Re: what is wrong with my if? [In reply to] Can't Post

Tried that too... it does the same thing!



Jasmine
Administrator / Moderator

Feb 22, 2001, 9:23 AM

Post #4 of 4 (498 views)
Re: what is wrong with my if? [In reply to] Can't Post

The $FORM::part is not working because it is looking in a separate package named FORM for scalar $part.


Code
package FORM; 
$part = 3;

package main;
$FORM = "test";

print "$FORM::part"; #prints 3

To get around this, just escape one of the :


Code
if ( $thing =~ /($FORM\::part|AI)/ig && $thing =~ /SMP/ig ){ 
print "match found\n";
}
else {
print "match not found\n";
}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives