When you're passing arrays and hashes into and out of subs, it's (normally) necessary to pass a reference to the array, rather than the array itself.

If you don't pass a reference, the array is flattened, and passed out as a simple list - not something you want in this case.

You can correct this by having the GetLogFilesAndDatesIntoArray sub return a reference to the AoA, rather than trying to flatten the AoA and then return it. This is easy to do - just change the return to return \@filesanddates;.

Once you have the sub returning a reference, you should assign it to a scalar variable, rather than an array (a reference is always a scalar, regardless of what it refers to), and you can then use this variable to pass the array into the ExtractData sub - like this:

# note: $datalist now, it's a reference $datalist = GetLogFilesAndDatesIntoArray($logdirectory); ExtractData($datalist); # passes the reference into the sub

Finally, once you have the reference going into the ExtractData sub, you can deference it to retrieve the original array like this:

my $_filesanddates = shift; @filesanddates = @$_filesanddates; # dereferences the reference

There's a whole load of stuff on references and subroutines in perlsub and perlref.

Update: Thanks to broquaint for pointing out that I'm talking absolute rubbish .. oh well, eh. References are still a Good Thing in my book, but I guess that's a preference now, rather than a requirement...

Hope that helps a little ...
-- Foxcub
A friend is someone who can see straight through you, yet still enjoy the view. (Anon)
All code is untested unless explicitly stated otherwise.


In reply to Re: Passing Array of Arrays by Tanalis
in thread Passing Array of Arrays by marctwo

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.