develooper Front page | perl.perl5.porters | Postings from January 2011

Re: Using smart matching to find whether an array contains a string

Thread Previous | Thread Next
From:
Abigail
Date:
January 26, 2011 07:19
Subject:
Re: Using smart matching to find whether an array contains a string
Message ID:
20110126151920.GR8853@almanda
On Wed, Jan 26, 2011 at 02:22:02PM +0000, Ed Avis wrote:
> Brad Baxter <bmb <at> mail.libs.uga.edu> writes:
> 
> >>>    perl -E '@a = ("1"); say "1 x" ~~ @a'
> 
> >>This is a slightly unperlish distinction; usually in Perl it doesn't matter
> >>whether a scalar holds the number 42 or the string '42'
> 
> >Perhaps I misunderstand the example, but there is no time that I'm aware
> >of when perl would store "1 x" in a scalar as a number.
> 
> I was referring to this difference:
> 
>     % perl -E '@a = ("1"); say "1 x" ~~ @a'
> 
>     % perl -E '@a = (1); say "1 x" ~~ @a'
>     1
> 
> So you have to be aware of the difference between 1 and '1'.
> This is the only place in everyday Perl programming where the difference is
> noticeable.


False, unfortunally.

    $ perl -wE 'say 10 | 33'
    43
    $ perl -wE 'say "10" | "33"'
    33
    $

And it can even be more subtle:

    $ perl -E '$a = $b = "abc100"; 0 + $b; say $a; say $b;
                             $a ++; $b ++; say $a; say $b'
    abc100
    abc100
    abc101
    1
    $




Abigail

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About