An example of the
NetWallah's suggestion:
package Foo;
use strict;
use Exporter 'import';
# Export on demand, so the caller knows
# where these came from.
our @EXPORT_OK = qw(get_array populate_array);
{
my @array; # can only be accessed in this block
sub get_array { \@array }
sub populate_array { @array = 'a' .. 'h' }
}
1;
Then to try it in the Perl debgugger:
% perl -de0
Loading DB routines from perl5db.pl version 1.37
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(-e:1): 0
DB<1> use Foo qw(get_array populate_array)
DB<2> x get_array()
0 ARRAY(0x7fa9ac81a298)
empty array
DB<3> populate_array()
DB<4> x get_array()
0 ARRAY(0x7fa9ac81a298)
0 'a'
1 'b'
2 'c'
3 'd'
4 'e'
5 'f'
6 'g'
7 'h'
DB<5>