Indeed, the OP's function does that, but OP attempts to accept them as multiple arrays at line 23: my (@overall, @electronics, @safety) = breakouts(@products)­;

This mixing of metaphors needs to be fixed one way or the other, and I suggest that, since OP wants to export globals, the right way to fix it is to directly load the globals instead of creating lexicals to shadow them. I am surprised that perl does not warn about this; OP does use warnings;.

This also leads to a third option, which is the C way of passing references to breakouts and having it populate the arrays passed as arguments, but I think the oft-seen quip "Keep It Simple, Stupid" applies here: breakouts is not some general function, but sorts specifically this data into these bins. A better architecture would involve replacing the whole thing with an SQL database (start with DBI and DBD::SQLite and move up to DBD::Pg when needed) but OP seems to want these arrays for some reason.


In reply to Re^5: Returning arrays from a package by jcb
in thread Returning arrays from a package by sherab

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.