[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] FNG



Chris, 

There are two kinds of null, defined and undefined. Null does not
necessarily mean undef. A null scalar in a integer context is 0, a null
scalar in a string context is ''. In $x you have an undefined value. In
$w you have an defined value, null. In the print statement, you are
forcing $w to a string context, where it gets evaluated and printed as a
null *string*. Try using %d and see what happens.

#!perl

$w = /a/;
$x = undef;

for ($w, $x) {
  printf "%d => %d\n", $_, ~$_;
  printf "%s => %s\n", $_, ~$_;
  printf "%u => %u\n", $_, ~$_;
 }

Yields:
0 => -1
 => 4294967295
0 => 4294967295
0 => 0
 => 
0 => 0

Ignoring warnings as well. Even though it's a big no-no. That's what the
-w switch is there for. :) Sorry, couldn't resist.

Notice that printf %d gives a signed value and %u gives us the unsigned
version.

Geoff

Chris Nandor wrote:
> 
> At 15.41 -0500 1999.01.27, Geoffrey C Kinnel wrote:
> >> >  1) the substitution fails, returning a 0 (the number of substitutions)
> >>
> >> It does not for me.  See below.
> >
> >Yes is does. See below :).
> 
> No, it doesn't.  :)
> 
> >$x = int(s/%40/@/);
> >
> >When forced to an integer context, it is 0. So when Perl needs an
> >integer, it makes an integer out of that value, though it may be null in
> >a string context. The scalar is defined, but null. In an integer
> >context, that's 0, in a string context, that's null (or'').
> 
> Well, not really.
> 
>   #!perl -wl
>   $w = (/a/);
>   $x = undef;
>   $y = '';
>   $z = 0 + '';
>   for ($w, $x, $y, $z) {
>     printf "%s => %s\n", $_, ~$_;
>   }
> 
> Ignoring warnings, we get:
> 
>    => 4294967295
>    =>
>    =>
>   0 => 4294967295
> 
> If $w contained the null string (or undef), it would not have printed
> 2**32-1 for ~$_.  But if it contained 0, then it would not have printed
> nothing for $_.  0 clearly is not returned.  The null string clearly was
> not returned.  My best guess is that it is some other kind of null, a null
> number.

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch