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

Re: [MacPerl] In the continuing vein of substitution....



At 17.16 -0500 1998.12.23, Mark Manning/Muniz Eng. wrote:
>Try this:
>
>#!/usr/local/bin/perl
>
>    @a = <<END_NUMBERS;
>0
>1
>2
>3
>4
>5
>6
>7
>8
>9
>10
>END_NUMBERS
>
>    print "Yes\n" if @a =~ /10/;
>    print "No\n" if @a !~ /10/;
>
>    undef @a;
>
>    for( $i=0; $i<=10; $i++ ){
>        $a[$i] = $i + 1;
>        }
>
>    print "Yes\n" if @a =~ /10/;
>    print "No\n" if @a !~ /10/;
>    exit( 0 );
>
>The answers are "No" and "No";  However, Chris' example of:
>
>	@a = 0..9;
>	print "Yes\n" if @a =~ /10/;
>
>Returns "Yes".  Go figure.  :-)
>
>My input on the above is that the first example converts the numbers to
>letters.  The second example though clearly does arithmetic (adding one
>to the number) and therefore should be saved as a number (ie: 1-11).  So
>it should be stored like Chris' example and should return "Yes" anyway.
>But it doesn't.  :-)

No.  In the first case, @a has one element, so scalar(@a) is 1.  So these
are both true:

  @a == 1;
  @a =~ /^1$/;

In the second case, @a has 11 elements, so scalar(@a) is 11, so these are true:

  @a == 11;
  @a =~ /^11$/;

--
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