Pry, Jeffrey <[email protected]> asked:
> Now, I was wondering if it would be possible to store a hash inside of
> an array.
Sure, just use the anonymous hash constructor {}, i.e. like
$settings[$i] = { 'ftpserver' => localhost, 'password' => 'p...@$$word' };
Or add/change individual keys in the hash
$settings[$i]->{ 'username' } = 'anonymous';
Or store the hash inside a hash
my %host_settings = (
'localhost' => { 'password' => 'p...@$$word' },
'ftp.cdrom.com' => { 'username' => anonymous, password = '[email protected]' },
);
Then you could say
my $host = 'ftp.cdrom.com';
print "Known settings for $host:\n"
foreach my $parameter ( keys %{ $host_settings{ $host } } ){
print " - $parameter: " . $host_settings{ $host }->{ $parameter } . "\n";
}
Or store a hash inside an array inside a hash inside an array...
push @slightly_silly_example, { 'key' => [ { 'some' => 'text' } ] };
Whatever you're doing, go check out Data::Dumper. It's invaluable when you're
hitting a snag working with nested data structures.
HTH,
Thomas
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/