The keys and values in hashes can only be scalars, you can't directly store a array as a value. But, you can store a refrence to a array in a hash (a reference is a scalar) which is what btrott's code does.
When you want to make a reference to another variable use the \ operator.
Or if you don't want to make a variable and then make a reference, you can initialize them this way.my $ref_to_array = \@an_array; my $ref_to_hash = \%a_hash; my $ref_to_scalar = \$a_scalar;
The contents can be retrieved like:my $ref_to_array = [1,2,3,4]; my $ref_to_hash = { 'key1' => 'val1', 'key2' => 'val2' }; my $ref_to_scalar = \"some string\n";
All this stuff is explained in the o'reily (sp?) books in great detail. I'd suggest getting them. :)print $ref_to_array->[0]; print $ref_to_hash->{'some_key'}; print ${$ref_to_scalar};
/\/\averick
In reply to RE: Re: Using an array in a hash
by maverick
in thread Using an array in a hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |