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

Re: [MacPerl] FNG



I feel I should defend myself here. :)

Christian Brechbuehler wrote:
> 
> Excerpt of followup (sent 27 January 1999) by Geoffrey C Kinnel:
> 
> >  0) There is no string specified to search (because =~ was not used) so
> > the substitution tries to operate on nothing
> 
> No, the substitution operates on $_, which in the above program has the
> undefined value.

I know that, but poor Kevin is just starting with Perl, and I thought I
would gloss over that little detail. $_ would mean nothing to him, and
since it's undefined in this case, it's sort of "nothing".

> 
> >  1) the substitution fails, returning a 0 (the number of substitutions)
> 
> It does not for me.  See below.

Yes is does. See below :).

> Sure I get the number of substiturions performed when it succeeds.
> But when it fails, I get a weird kind of empty string.  The following
> program,
> 
>     1      #! /usr/local/bin/perl -w
>     2
>     3      $_ = "no match";
>     4      $x = s/%40/@/;
>     5      $y = "";
>     6      $notx = ~$x;
>     7      $noty = ~$y;
>     8      $str_equal = $x eq $y;
>     9      $num_equal = $x == $y;
>     10
>     11   print "'$x', '$y', $str_equal, $num_equal, '$notx', '$noty'\n";
> 

> First, $x is a string.  Then it is a number. My question: How many
> kinds of "scalars" exist?

try this on line 4:
$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''). 

Geoff

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