in reply to PUSH Question
You can only ever push onto an array.
push @{ $config->{groups}->{$last_group} }, $line;
could have been written as
my $ref_to_array = $config->{groups}->{$last_group} push @$ref_to_array, $line;
if that helps.
Some reference material:
perlref
perllol
References Quick Reference
Dereferencing Syntax
Update: Oops, those two snippets aren't the same due to autovivification.
my $ref_to_array = $config->{groups}->{$last_group} push @$ref_to_array, $line; # In case $ref_to_array was autovivified, $config->{groups}->{$last_group} = $ref_to_array;
Or vivify it explicity,
my $ref_to_array = $config->{groups}->{$last_group} ||= []; push @$ref_to_array, $line;
That kind of confuses the point, which was that the expression within the curlies returns an array reference, which is derefenced by @{}, resulting an array being passed to push.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: PUSH Question
by emusic32 (Initiate) on Aug 16, 2008 at 14:40 UTC | |
by FunkyMonk (Bishop) on Aug 16, 2008 at 15:58 UTC | |
by ysth (Canon) on Aug 17, 2008 at 05:54 UTC |