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

Re: key value hash slices in strings

Thread Previous
From:
Brad Gilbert
Date:
June 16, 2013 16:21
Subject:
Re: key value hash slices in strings
Message ID:
CAD2L-T3sokAWtLpGDdXZ_C-z=2u7UVZEzXXMgcn_G=j5+Eaa6g@mail.gmail.com
On Sun, Jun 16, 2013 at 4:21 AM, Ruslan Zakirov <ruz@bestpractical.com> wrote:
>
> Hi,
>
> Not sure what to do in the following case:
>
> $ ./perl -Ilib/ -E 'my %h = 1..10; say qq{ %h{"1","3"} }'
>  %h{"1","3"}
> $ ./perl -Ilib/ -E 'my %h = 1..10; say qq{ @h{"1","3"} }'
>  2 4
>
> Probably it should be left alone as the following doesn't work:
>
> $ ./perl -Ilib/ -E 'my %h = 1..10; say qq{ %h }'
>  %h
>
> Enabling interpolation will probably cause troubles.
>

If  someone really wanted that to happen, they could surround the kv
slice with @{[ ]}

    $ perl -E 'my %h = 1..10; say qq{ @{[ %h{"1","3"} ]} }'

    $ perl -E 'my %h = 1..10; say qq{ @{[ %h ]} }'

Thread Previous


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