From: Slickuser on
my @ar = ('x','1','y','z');
my %hashVar =
(
'key1' => [qw(1 2 3 4 5 5 6 7 8 9)],
'key2' => [qw(a b c d e) ]
);

@ar values are being populate my parsing a file and get push in.

How do I add @ar into 'key2'?
so it will contain a b c d e x 1 y z

Thanks.
From: Martijn Lievaart on
On Wed, 17 Mar 2010 00:06:09 -0700, Slickuser wrote:

> my @ar = ('x','1','y','z');
> my %hashVar =
> (
> 'key1' => [qw(1 2 3 4 5 5 6 7 8 9)], 'key2' => [qw(a b c d
e) ]
> );
>
> @ar values are being populate my parsing a file and get push in.
>
> How do I add @ar into 'key2'?
> so it will contain a b c d e x 1 y z

push @{$hashVar{key2}}, @ar;

Or more clearly:

my $arrayref = $hashVar{key2};
push @$arrayref, @ar;

HTH,
M4
From: Sherm Pendley on
Slickuser <slick.users(a)gmail.com> writes:

> my @ar = ('x','1','y','z');
> my %hashVar =
> (
> 'key1' => [qw(1 2 3 4 5 5 6 7 8 9)],
> 'key2' => [qw(a b c d e) ]
> );
>
> @ar values are being populate my parsing a file and get push in.
>
> How do I add @ar into 'key2'?
> so it will contain a b c d e x 1 y z

push @{$hashVar{'key2'}}, @ar;

See also:

perldoc perlref
perldoc perllol

sherm--
From: Jens Thoms Toerring on
Slickuser <slick.users(a)gmail.com> wrote:
> my @ar = ('x','1','y','z');
> my %hashVar =
> (
> 'key1' => [qw(1 2 3 4 5 5 6 7 8 9)],
> 'key2' => [qw(a b c d e) ]
> );

> @ar values are being populate my parsing a file and get push in.

> How do I add @ar into 'key2'?
> so it will contain a b c d e x 1 y z

Others have pointed out how to stuff it into the array pointed
to by the 'key2' element when it already exists, but you can do
it also when creating the hash, using

my %hashVar =
(
key1 => [ qw( 1 2 3 4 5 5 6 7 8 9 ) ],
key2 => [ qw( a b c d e ), @ar ]
);
Regards, Jens
--
\ Jens Thoms Toerring ___ jt(a)toerring.de
\__________________________ http://toerring.de