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

Re: [MacPerl] Novice question regards subroutines



At 18.52 -0400 1998.09.19, Bruce Van Allen wrote:
>Please check your code again, following the examples from Steve. Use ==
>with numbers, _not quoted_, or eq with strings, quoted. If you use "1", the
>1 is not being compared as a number, but rather a string.

That is not true.

  #!perl -wl
  $x = 1;
  print "yes" if $x == "1";

If "1" were not numeric, this would print an error like so:

  # Argument "1" isn't numeric in eq.

But no error is printed, and "yes" is printed.  Perl does its best to see
if "1" can be made into a recognizable number before doing the comparison.
This even "works":

  #!perl -wl
  $x = 1e10;  # is this a number?
  print $x;   # print to see if it is a number, indeed
  print "yes" if $x == "1e10";  # can "1e10" in QUOTES
                                # be considered a NUMBER?  i guess so ...

Returns:

  10000000000
  yes

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

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