what does "!" mean in a perl script?
Feb 15, 2001, 6:21 AM
Veteran (19537 posts)
Feb 15, 2001, 6:21 AM
Post #2 of 8
Views: 4464
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
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
Feb 16, 2001, 5:41 PM
Veteran (1509 posts)
Feb 16, 2001, 5:41 PM
Post #6 of 8
Views: 4441
!= 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.
Feb 17, 2001, 5:43 AM
Veteran (19537 posts)
Feb 17, 2001, 5:43 AM
Post #7 of 8
Views: 4400
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
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