>>>>> "Shlomi" == Shlomi Fish <[email protected]> writes:
Shlomi> <sts> just a short question. besides personal preference is there
Shlomi> any difference if you use if(! or unless(?
Shlomi> <rindolf> sts: no.
Shlomi> <rindolf> sts: they do the same thing.
That's actually not true.
if ($foo) vs unless (not $foo) will return a different "last expression
evaluated" if that happens to be the last expression in the subroutine,
since the last expression evaluated is the negation.
Specifically:
sub if {
my $foo = 0;
if ($foo) {
die "not reached";
3; # use this instead
}
}
sub unless {
my $foo = 0;
unless (not $foo) {
die "not reached";
3; # use this instead
}
}
use Data::Dumper;
print Dumper({ if => scalar &if(), unless => scalar &unless() });
==>
$VAR1 = {
'unless' => 1,
'if' => 0
};
Yeah, subtle, but you know how Perl is.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/