Gossamer Forum
Home : General : Perl Programming :

what does "!" mean?

Quote Reply
what does "!" mean?
what does "!" mean in a perl script?

Quote Reply
Re: what does "!" mean? In reply to
It kinda means...."if not defined" or "not equal to"

Eg.......

if(!$number) {
summat();
}
else {
summatelse();
}

This means if the $number variable isn't defined then do summat(); otherwise do summatelse();

.......or.........

if($number != "5") {
summat();
}
else {
summatelse();
}

....this means if the $number variable doesn't equal 5 then do summat(); otherwise do summatelse();






Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: what does "!" mean? In reply to
! = not equal to

same as ne.

Cheers
Wiliam Stephens

Quote Reply
Re: what does "!" mean? In reply to
no, it's not the same as 'ne', because != compares numeric values...ne compares string values.

example:

if ($num != 5)
#do something;

if ($string ne "something")
#do something;

-Corey



Corey Breitfelder
-->cgismtih.hypermart.net
Quote Reply
Re: what does "!" mean? In reply to
Actually ! can also be used to compare string values as well.

Regards,

Eliot Lee
Quote Reply
Re: what does "!" mean? In reply to
In Reply To:
Actually ! can also be used to compare string values as well.
In the contect of if (! $string) { it can, but not in a context of !=

!= is for numerics, ne is for strings. Same thing as with == and eq. They should not be interchanged.

Example:

$n = 'mark';
$p = 'Mark';

print 'no match' if $n != $p;

that won't print anything, but $n ne $p will.

--mark

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: what does "!" mean? In reply to
What is the difference if any between

print 'no match' if $n != $p;

and

if ($n != $p) {
print "No Match";
}

Will it affect the speed of the script or anything else?

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: what does "!" mean? In reply to
functionally no difference. Speedwise, very micro difference.

the one line version is more compact, just as readable, and more Perl-ish.

--mark

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.