in reply to How do I loop through a multidimensional array?

Thank you very much! You're correct, those other errors where typos generated by a combination of too much sleep and too little coffee (or was it the other way around?) when simplifying the question into an example. Your suggestion was just the elegant solution I was looking for, thanks! The corrected example would then be:
$items[0]{title} = "Song 2"; $items[0]{artist} = "Blur"; $items[1]{title} = "The Call of Khtulu"; $items[1]{artist} = "Metallica"; foreach $item (@items) { print $item->{artist}; print $item->{title}; }

Replies are listed 'Best First'.
Re: Answer: How do I loop through a multidimensional array?
by davorg (Chancellor) on Jul 04, 2001 at 15:34 UTC

    Actually, your data structure initialisation could be a little more elegant too. Try this:

    my @items = ({ title => 'Song 2', artist => 'Blur' }, { title => 'The Call of Khtulu', artist => 'Metallica' });

    Oh, and I knew that Metallica aren't very intelligent, but can they really not spell "Cthulhu"?

    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>