in reply to Returning arrays from a package

Your problem is simple: you are declaring the arrays that you want to export as lexicals instead of globals in your code. Exporter then accesses the globals and ends up exporting empty arrays.

Try our (@overall, @electronics, @safety); breakouts(@products); at line 23.

You will also need to rework breakouts to directly load the arrays, instead of creating locals and attempting to return those. You cannot return multiple lists from a function in Perl — perl will merge them all into a single flat list and put it all in the first array.

Replies are listed 'Best First'.
Re^2: Returning arrays from a package (feature qw/refaliasing/;)
by LanX (Saint) on Oct 02, 2019 at 00:15 UTC
    Please allow me to nitpick a bit and to advertise an experimental feature

    > You cannot return multiple lists from a function in Perl

    well the OP is trying to return multiple array-refs not lists, and the new'ish use feature qw/refaliasing/; allows these to be assigned to multiple @arrays. (see tst2())

    use strict; use warnings; use Data::Dump qw/pp dd/; use feature qw/refaliasing/; no warnings "experimental::refaliasing"; sub tst { (\my %args) = @_; pp \%args; } tst({a=>1,b=>2}); sub tst2 { return [1..3],[4..7] } our (@a,@b); (\@a,\@b) = tst2(); pp \@b; pp \@a;

    { a => 1, b => 2 } [4 .. 7] [1, 2, 3]

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      While we are nitpicking, I will note that the experimental refaliasing feature seems to just make references into lvalues, such that tst2 is actually returning a flat list of arrayrefs, rather than multiple lists. You still cannot return multiple lists in Perl. Oh, and did I mention it is an experimental feature? :-)