in reply to Passing Hashes In and Out of Functions
1) The reason this isn't working is because those hashes that you're returning are flattened into a big list, which is then assigned to the *first* hash in the list you're assigning to. The rest of the hashes get undefined. Read perlman:perlsub for more details.
2) The second problem is that you probably don't want to do it like this, anyway. Investigate using an array of hash references to hold your data, something like this:
Now you can access your data like:@assign = ( { title => "Slashdot", category => "Tech News", blurb => "News for nerds. Stuff that matters.", url => "http://www.slashdot.org/" }, { title => "Perl Monks", category => "Perl", blurb => "Perl advice.", url => "http://www.perlmonks.org/" } );
Or, if you want a particular field of a particular site,for my $site (@assign) { print "Site:\n"; for my $field (keys %$site) { print "\t", $field, " = ", $site->{$field}, "\n"; } }
Read perlman:perlref or perlreftut for more details on using references.print "Title: ", $assign[0]{title}, "\n";
(And think about returning a reference from your subroutine rather than the actual hash/array.)
|
|---|