develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #54728] PathTools-3.27 triggers a bug in Perl

Thread Previous | Thread Next
From:
Lukas Mai
Date:
August 4, 2013 13:51
Subject:
Re: [perl #54728] PathTools-3.27 triggers a bug in Perl
Message ID:
51FE5C63.1040906@gmail.com
On 04.08.2013 15:12, Alexandr Ciornii wrote:
> This ticket can be viewed as two tickets:
> 1. Bug in PathTools (fixed)
> 2. This problem:
> #!perl
>
> "2" =~ m/(.*)/;
> print test1("1", $1), "\n";
>
> sub test1 {
>    'aa' =~ m/(.)/;
>    return $_[0].'/'.$_[1];
> }
> prints "1/a" on perl 5.18.0.
>
> Can it be considered a bug?

I don't see it as a bug.

1) "2" =~ m/(.*)/ sets $1 to "2".
2) test1("1", $1) calls test1 with "1" and $1.
3) 'aa' =~ m/(.)/ sets $1 to "a".
4) $_[0].'/'.$_[1] builds a string from the arguments passed to test1.
    Perl passes arguments by alias.
    $_[0] is an alias to "1".
    $_[1] is an alias to $1, which currently contains "a".
5) Thus test1 returns "1/a".
6) Match variables are implicitly localized, so $1 reverts to "2" here.
7) "1/a\n" is printed.

-- 
Lukas Mai <plokinom@gmail.com>

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