Hi all, I'm trying to work out where I'm going wrong with my data structures. I want to create a hash of lists of lists - i.e.
%datastructure=( 'foo' => [ [ 'foo01', 'foo02' ], [ 'foo11', 'foo12' ] ], 'bar' => [ [ 'bar01', 'bar02' ], [ 'bar11', 'bar12' ] ] );
From this, Data::Dumper gives me:
$VAR1 = 'foo'; $VAR2 = [ [ 'foo01', 'foo02' ], [ 'foo11', 'foo12' ] ]; $VAR3 = 'bar'; $VAR4 = [ [ 'bar01', 'bar02' ], [ 'bar11', 'bar12' ] ];
So far, so good. Now, what I want to do is shift out the first list from the 'foo' record, (i.e. return me the list ('foo01', 'foo02'), and remove that entry from the datastructure). The code I'm using for this is as follows:
my @entry = shift(@{@datastructure{'foo'}});
Now, this appears to work in that it removes the correct information from the data structure; however, rather than return it as a simple list, it returns it as a list which contains one element which is the list that I want (i.e. a LoL). This is confirmed by Data::Dumper - @entry is printed as:
$VAR1 = [ 'foo01', 'foo02' ];
Whereas creating a list manually:
@my_list = ('foo01', 'foo02');
gives:
$VAR1 = 'foo01'; $VAR2 = 'foo02';
So, how do I get my LoL into just a simple list?
Dumper(@entry);
gives:
$VAR1 = [ 'foo01', 'foo02' ];
whilst
Dumper(@entry->[0]);
also gives:
$VAR1 = [ 'foo01', 'foo02' ];
but
Dumper(@entry->[0]->[0]);
gives:
$VAR1 = 'foo01';
i.e. I can get either a LoL or a single element, but nothing inbetween. I'm confused!

In reply to Data structures problem by MrFlibble

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.