Several things here:
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:
@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/"
}
);
Now you can access your data like:
for my $site (@assign) {
print "Site:\n";
for my $field (keys %$site) {
print "\t", $field, " = ", $site->{$field}, "\n";
}
}
Or, if you want a particular field of a particular site,
print "Title: ", $assign[0]{title}, "\n";
Read perlman:perlref or perlreftut for more details on
using references.
(And think about returning a reference from your subroutine
rather than the actual hash/array.) |