[Wellington-pm] Strange (for me) notation

Kent Fredric kentfredric at gmail.com
Wed Jul 22 21:08:51 PDT 2009


On Thu, Jul 23, 2009 at 3:49 PM, Jacinta Richardson <
jarich at perltraining.com.au> wrote:

> Sam Vilain wrote:
>
>  But surely you want to know another way, using scalar:
>> $ib->{reg}{scalar LATEST_D_ACROSS_PRODUCTS}
>>
>
> You might also see:
>
>        $ib->{reg}{ LATEST_D_ACROSS_PRODUCTS . "" }
>
> but I think the @{[ ... ]} is cute, but terrible.  This is the same trick
> required for __PACKAGE__ and similar.
>

Of course, you don't want to be using that in the event LATEST_D_WHATEVER is
in fact an array-returning constant doing parallel hash assignment :)

#!/usr/bin/perl
use strict;
use warnings;

use Moose::Autobox;

local $Data::Dumper::Indent = $Data::Dumper::Indent = 0;
local $Data::Dumper::Terse  = $Data::Dumper::Terse  = 1;

sub FOO() {
  'bar', 'baz';
}

my %hash;

@hash{ (FOO) } = ( 1, 2 );

%hash->dump->say; # {'bar' => 1,'baz' => 2}

@hash{ FOO() } = ( 3, 4 );

%hash->dump->say; # {'bar' => 3,'baz' => 4}

@hash{FOO} = ( 5 ); # Scalar value @hash{FOO} better written as $hash{FOO}
at /tmp/ex.pl line 24.

%hash->dump->say; # {'bar' => 3,'baz' => 4,'FOO' => 5}

@hash{FOO . "" } = ( 6 );

%hash->dump->say; # {'bar' => 3,'baz' => 6,'FOO' => 5}

@hash{FOO . "" } = ( 7, 8 );

%hash->dump->say; # {'bar' => 3,'baz' => 7,'FOO' => 5}


-- 
Kent

perl -e  "print substr( \"edrgmaM  SPA NOcomil.ic\\@tfrken\", \$_ * 3, 3 )
for ( 9,8,0,7,1,6,5,4,3,2 );"

http://kent-fredric.fox.geek.nz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/wellington-pm/attachments/20090723/eaf5ff06/attachment.html>


More information about the Wellington-pm mailing list