Pry, Jeffrey <jeffrey....@sig.com> 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 = 'w...@r.es' },
  );

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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to