(ar0n) Re: I've never seen this syntax before
by ar0n (Priest) on Apr 04, 2001 at 23:18 UTC
|
It returns the inverse of whatever Execute($cmd) returns. If Execute($cmd) returns true, the sub returns false and vice versa.
[ar0n]
| [reply] [d/l] [select] |
|
| [reply] [d/l] |
|
If the operand is 0, a string beginning with "0", a null string, or undef the result is 1, otherwise the result is a null string.
| [reply] |
|
|
Thanks, that was what I thought, but there is no return in the Execute() sub, so it looks like it's useless code.
Your Humble Servant,
-Chuck
| [reply] |
|
No necessarily useless... the last line of a subroutine becomes its return value if none is specified explicitly... so:
<CODE>
sub foo {
1;
}
#and
sub foo2 {
return 1;
}
both return 1
- Ant
| [reply] |
|
| [reply] |
|
Re: I've never seen this syntax before
by dws (Chancellor) on Apr 04, 2001 at 23:30 UTC
|
If the intent is to return false if $cmd executes correctly, the code you've shown is badly, badly broken. print is going to return 1 regardless of whether `$cmd 2>&1`; executes correctly, and regardless of whatever ends up in $txt.
Look downstream of the return, and see if any callers are actually using the return value, and whether they think it has anything to do with the command executing properly. You may get to replace Execute with something that works. Fortunately, that's an easy fix. I'll leave it as a learning exercise.
| [reply] [d/l] [select] |
Re: I've never seen this syntax before
by suaveant (Parson) on Apr 04, 2001 at 23:24 UTC
|
no... the 2>&1 redirects stderr to stdout, so stderr and stdout from the command goes into $txt. if the sub ends with a print, the print will always return true unless it was unable to print. So the sub will probably almost always return true, the not will make the funtion return false. If it can't print, the return will be true... odd code...
- Ant | [reply] [d/l] |
|
I now see what's going on here. There is no || die on the file open. This freaky thing is testing to see if the file opened AFTER trying to write to it. Cool I can rip it out and put a file open || die in there.
Good thing the guy who wrote this doesn't work here anymore.
Your Humble Servant,
-Chuck
| [reply] |
(boo)Re: I've never seen this syntax before
by boo_radley (Parson) on Apr 04, 2001 at 23:36 UTC
|
Remember that perl will implicitly return the sub's last operation's result.
So, what you're seeing is someone printing something, and then notting the success of the print. Which is, uh, odd, since print usually works unless something uniquely catastrophic has happened.
compare
print print "foo\n";
and
print not print "foo\n";
.
| [reply] [d/l] [select] |
Re: I've never seen this syntax before
by cLive ;-) (Prior) on Apr 04, 2001 at 23:23 UTC
|
if (Execute($cmd)) {
return 0;
}
else {
return 1;
}
cLive ;-) | [reply] [d/l] |
|
return 0; should be return "";
| [reply] [d/l] [select] |
|
It doesn't matter. I can return "0", 0, or "" for false. They are equivalent in a boolean context.
cLive ;-)
| [reply] |
|
|
Actually it is more subtle than even that. You can't
replace !1 with 0 nor with
"".
0 is wrong because, in a string context,
!1 is "" while 0
is "0".
"" is wrong because, when warnings are turned
on, 0+"" generates q(Argument "" isn't numeric)
while 0+!1 is silent.
-
tye
(but my friends call me "Tye")
| [reply] [d/l] [select] |