On 2010.03.26 09:02, Pry, Jeffrey wrote: > I want to use the array because I have multiple ftp servers that can be > called from a dropdown box. Is it possible to do this with just a hash?
It is possible: #!/usr/bin/perl use strict; use warnings; my %config; # each server info is a hash reference that contains the specifics of # the server in question my $server1_info = { ftpserver => 'localhost', ftpuser => 'steve' }; my $server2_info = { ftpserver => 'remote', ftpuser => 'dave' }; my $server3_info = { ftpserver => 'myhost', ftpuser => 'blah' }; # load the top-level %config hash with each server $config{ server1 } = $server1_info; $config{ server2 } = $server2_info; $config{ server3 } = $server3_info; # we have a hash (%config) who's keys contain another hash reference, # (the server info) which in turn contains the server name and username # print out server2 while ( my ( $directive, $value ) = ( each %{ $config{ server2 } } )) { print "$directive: $value\n"; } # fetch and print out just the server name of server3 my $server3_name = $config{ server3 }{ ftpserver }; print "Name: $server3_name\n"; Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/