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 08:31
Subject:
Re: Using smart matching to find whether an array contains a string
Message ID:
20110126163117.GS8853@almanda
On Wed, Jan 26, 2011 at 04:19:12PM +0000, Ed Avis wrote:
> Abigail <abigail <at> abigail.be> writes:
> 
> >>     % perl -E '@a = ("1"); say "1 x" ~~ @a'
> >> 
> >>     % perl -E '@a = (1); say "1 x" ~~ @a'
> >>     1
> 
> >>This is the only place in everyday Perl programming where the difference is
> >>noticeable.
> >
> >False, unfortunally.
> >
> >    $ perl -wE 'say 10 | 33'
> >    43
> 
> Ah - I do not use the | operator in everyday programming (in fact, I don't think
> I have ever used it) so I didn't think of this case.

Never did something like

    flock $fh, LOCK_EX | LOCK_UN;

    sysopen $fh, "foo", 0666, O_CREAT | O_EXCL;

    if ($? & 127) {say "Coredump"}

?

> 
> >And it can even be more subtle:
> >
> >    $ perl -E '$a = $b = "abc100"; 0 + $b; say $a; say $b;
> >                             $a ++; $b ++; say $a; say $b'
> 
> That is a nasty one.  Surely the expression 0 + $b should not mutate the value
> of $b.  I'm surprised this is not considered a bug?


I'm pretty sure I'd like $b to get a numerical value if I use it in
numeric context.


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