Re: Perl Peeves



On 2009-01-28, Peter J. Holzer <hjp-usenet2@xxxxxx> wrote:
On 2009-01-27 09:08, Eric Pozharski <whynot@xxxxxxxxxxxxxx> wrote:
On 2009-01-27, Tim McDaniel <tmcd@xxxxxxxxx> wrote:
(5) That "special false". I was going nuts trying to figure out what
was different between

[ '' in string context, 0 in numeric context ]

That special false is evaluated to blah-blah-blah *immediately* since
the context is known at compile time (am I right?).

No. Consider:

#!/usr/bin/perl
use warnings;
use strict;

my $bool = (1 < 0);

if (rand() < 0.5) {
print "<$bool>\n";
} else {
print 0 + $bool, "\n";
}

No, special false is sticky. That explains better though, I think.

perl -wle '
my($nil, $empty) = (0, q||);
print qq|<$nil> <$empty>|;
print 0 + $nil;
print 0 + $empty;
'
<0> <>
0
Argument "" isn't numeric in addition (+) at -e line 5.
0

p.s. IOW -- me wrongs.


--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
.



Relevant Pages

  • Re: Easter radio project
    ... digital multi-band transceiver from an old electric razor, an empty ... sardine tin, a pair of bicycle clips and some sticky back plastic. ...
    (uk.radio.amateur)
  • Re: Easter radio project
    ... digital multi-band transceiver from an old electric razor, an empty ... sardine tin, a pair of bicycle clips and some sticky back plastic. ...
    (uk.radio.amateur)
  • Re: Extracting one record from multiple-records textfile
    ... use strict; ... In particular, Jeff, I'm trying to ... I get output (if I don't do that $content is empty). ... Because you are changing the Input Record Separator and you have empty ...
    (perl.beginners)
  • Re: While query
    ... || Hash: SHA1 ... || Oops--this won't actually empty the array as the various pop-based ...
    (comp.lang.perl.misc)
  • Re: Easter radio project
    ... digital multi-band transceiver from an old electric razor, an empty ... sardine tin, a pair of bicycle clips and some sticky back plastic. ...
    (uk.radio.amateur)