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

Re: [MacPerl] find value in array



On Wed, Oct 18, 2000 at 08:38:15AM -0700, John W Baxter wrote:
> >On Tue, Oct 17, 2000 at 11:18:07PM -0700, Bruce Van Allen wrote:
> >> At 1:48 PM 10/17/00, Ronald J Kimball wrote:
> >> >
> >> >I still prefer returning '0 but true' to avoid this problem, the way some
> >> >of Perl's builtin functions do, rather than returning a reference.
> >>
> >> Cool. The expression $list['0 but true'] works like $list[0] !!
> >
> >Perl even goes so far as to special case the string '0 but true'; when it
> >is converted to a number, Perl does not produce an "argument is not
> >numeric" warning.
> 
> That's not a special case...try

Yes, it is.


> print 0 + "77 seventy-seven" + "\n";

~> perl -we 'print 0 + "77 seventy-seven" + "\n";'
Argument "77 seventy-seven" isn't numeric in add at -e line 1.
Argument "\n" isn't numeric in add at -e line 1.
77~> 
 

Now try:

perl -wle 'print "0 but true" + "77 seventy-seven"'


> When a number is needed and Perl has a string, it converts as much of the
> string as possible to a number and uses that.

And, if warnings are enabled and the string does not convert cleanly, Perl
produces a warning that the argument is not numeric.  Except when
converting the string '0 but true', which is a special case and does not
cause a warning.


Ronald

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org