Simple comparison statement that doesn't work

R

ranrodrig

Folks,

I want to make a variable null if an specific string is in another
variable, so i built the following statement:

$nmsg = "" if $IP =~ /\.image\s/;

but its not working, what i want to do on this is:

if the $IP == "image" then

make $nmsg null.

If you can give me a tip about how to fix this, that would ve very
appreciatted.

TIA & BR.
 
U

usenet

ranrodrig said:
$nmsg = "" if $IP =~ /\.image\s/;

That will match any occurance of a period (dot) followed by the word
"image" followed by a space (anywhere in $IP). That seems inconsistent
with your next statement (where you suggest an exact match of the plain
word "image").
but its not working, what i want to do on this is:

if the $IP == "image" then

== is numeric comparison. Use "eq" for string comparsion. See perldoc
perlop (this is one of my favorite careless mistakes to make, BTW).
make $nmsg null.

undef $nmsg if $IP eq 'image'; #exact string match
 
U

usenet

== is numeric comparison. Use "eq" for string comparsion. See perldoc
perlop (this is one of my favorite careless mistakes to make, BTW).

I should have mentioned, though, that when I make this mistake, I don't
get far with it, because I
use warnings;
and Perl responds with a warning such as:
Argument (whatever) isn't numeric in numeric eq (==) at...

You should use warnings, too. And use strict. It will catch a lot of
careless mistakes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top