Assigning anonymous hash to a list

Hernan Lopes hernanlopes at gmail.com
Wed Jul 31 02:34:13 BST 2013


ie:

my ( $first_thing_on_the_left, $second_thing ) = ( "first something" ,
{ second => 'something' } );

On 7/30/13, Hernan Lopes <hernanlopes at gmail.com> wrote:
> When you do that, you are implicitly saying:
>
> The thing on the left is equals the thing in the right.
> So, in the left you have 1 thing ( a list because of parenthesis ),
> and on the right, you have 2 things: string+object.
>
> Add parenthesis on the right and transform it into a list.
>
> After that perl will understand you are assinging the first thing on
> the list (from left) equals the first thing on the list (from right)
> and so on.
>
> []'s
>
> Hernan Lopes
>
> On 7/30/13, gvim <gvimrc at gmail.com> wrote:
>> Can anyone explain why this works:
>>
>> my $ref = {a => 1,  b => 2, c => 3};
>> say $ref->{b};     #  Result: 2
>>
>> ... but this doesn't :
>>
>> my ($str, $ref) = 'text', {a => 1, b => 2, c => 3};
>> say $ref->{b};   # Result: Use of uninitialized value
>>
>> Seems a little inconsistent.
>>
>> gvim
>>
>


More information about the london.pm mailing list