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

Re: [perl #117907] On RHS of s///, ${9} works but ${10} does not

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
May 7, 2013 14:35
Subject:
Re: [perl #117907] On RHS of s///, ${9} works but ${10} does not
Message ID:
20130507143537.GT2216@iabyn.com
On Tue, May 07, 2013 at 07:14:03AM -0700, Ed Avis wrote:
> I found this surprising:
> 
>     #!/usr/bin/perl
>     use 5.016;
>     use warnings;
>     use strict;
>     $_ = 'a' x 10;
>     s/(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)/${9}/ or die;
>     say $_;
>     $_ = 'a' x 10;
>     s/(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)/${10}/ or die;
>     say $_;
> 
> Why is ${9} accepted on the RHS of a substitution but ${10} not?
> They should both be or neither be.
> 
> The same applies in ordinary code:
> 
>     say ${9};    # ok
>     say ${10};   # fails

It's just the braced variant of the variable name (${10} verses $10, and
has been that way a long time:

$ perl589 -e'use strict; $9; ${9}; $10; ${10}'
Can't use string ("10") as a SCALAR ref while "strict refs" in use at -e line 1.

I don't know if there is any rationale behind this, but a first glance it
indeed seems like a bug.

-- 
O Unicef Clearasil!
Gibberish and Drivel!
    -- "Bored of the Rings"

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