Yes, mea culpa, Johathan is right. In addition to the typo, I didn't
recognize that the example given isn't a hash of hashes but only a
hash of arrays (I'm too used to doing hashes of hashes, which are just
so darn much fun).
foreach my $key1 (sort keys %facets) {
foreach my $key2 (@{$facets{$key1}}) {
print " $key1 / $key2 \n";
}
}
would do it. Shoulda tried it first, I guess!
Spencer
On 2/10/06, Spencer Anspach <[EMAIL PROTECTED]> wrote:
> foreach my $key1 (sort(keys(%facets))) {
> foreach my $key2 (sort(keys(%facets{$key1))) {
> print " $key1 / $key2 \n";
> }
> }
>
> Spencer
>
> On 2/10/06, Eric Lease Morgan <[EMAIL PROTECTED]> wrote:
> >
> > How do I loop through a reference to an array?
> >
> > I have the following data structure:
> >
> > my %facets = (
> > 'audiences' => [('freshman', 'senior')],
> > 'subjects' => [('music', 'history')],
> > 'tools' => [('dictionaries', 'catalogs')]
> > );
> >
> > I can use this code to get the keys for %facets:
> >
> > foreach my $key (sort(keys(%facets))) { print $key, "\n" }
> >
> > But since $key points to the reference of an array, I don't know how
> > to loop through the referenced array.
> >
> >
> > --
> > Eric Lease Morgan
> > Head, Digital Access and Information Architecture Department
> > University Libraries of Notre Dame
> >
> > (574) 631-8604
> >
> >
> >
> >
> >
>
>
> --
> Spencer M. Anspach, Library Systems Analyst/Programmer
> Library Information Technology, Indiana University
> Library E456 phone: (812) 856-5318
> Bloomington, IN 47405 fax: (812) 856-4979
> [EMAIL PROTECTED] pager: (812) 335-7403
>
--
Spencer M. Anspach, Library Systems Analyst/Programmer
Library Information Technology, Indiana University
Library E456 phone: (812) 856-5318
Bloomington, IN 47405 fax: (812) 856-4979
[EMAIL PROTECTED] pager: (812) 335-7403