Along with having an array reference as opposed to a hash reference, ref($aref) returns ARRAY, not LIST, so that'll never catch.

Here's a basic example for review and to do some testing with:

:
use warnings; use strict; my $struct = [ { 1 => 'a', 2 => 'b', }, [ 1, 2, 3, ], { 3 => 'c', 4 => 'd', }, ]; thing($struct); sub thing { my ($aref) = @_; for my $elem (@$aref){ if (ref $elem eq 'ARRAY'){ print "array:\n"; print "$_\n" for @$elem; } elsif (ref $elem eq 'HASH'){ print "hash:\n"; print "$_ => $elem->{$_}\n" for keys %$elem; } else { die "element is not an allowed ref\n"; } } }

Output:

hash: 1 => a 2 => b array: 1 2 3 hash: 3 => c 4 => d

In reply to Re: Stuck on a Perl assignment by stevieb
in thread Stuck on a Perl assignment by ickopicko

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.