Re: store Array in hash ?
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Wed, 29 Mar 2006 23:45:02 -0800
Michael Gale wrote:
Hello,
Hello,
I have setup a hash like the following:
my $test;
$test->{$setup}->{'opt'} = "OK";
Or:
my $test = { $setup => { opt => 'OK' } };
It works fine, now I want to save an array to the hash:
my @data;
push(@data,"test");
$test->{$setup}->{'data'} = @data;
That should be:
$test->{ $setup }{ data } = [ @data ];
Or:
@{ $test->{ $setup }{ data } } = @data;
Now how do I use it in a for loop later in the script, I tried:
for(my $c=0; $c < $test->{$setup}->{'data'}; $c++) {
for ( my $c = 0; $c < @{ $test->{ $setup }{ data } }; $c++ ) {
print $test->{$setup}->{'data'}[$c];
}
Or:
for my $item ( @{ $test->{ $setup }{ data } } ) {
print $item;
}
John
--
use Perl;
program
fulfillment
.
- Follow-Ups:
- Re: store Array in hash ?
- From: Mr. Shawn H. Corey
- Re: store Array in hash ?
- References:
- store Array in hash ?
- From: Michael Gale
- store Array in hash ?
- Prev by Date: Re: store Array in hash ?
- Next by Date: RE: store Array in hash ?
- Previous by thread: Re: store Array in hash ?
- Next by thread: Re: store Array in hash ?
- Index(es):