rocky13 has asked for the wisdom of the Perl Monks concerning the following question:

package One; $cache = {}; sub query { my $sql = "select first, last, phone, address from db..table where las +t like 'A%'"; data($sql); } sub data { my $sql = @_; my $dsn = "dbi:mysql:$database:$host:$port"; my $dbh = DBI->connect($dsn,$user,$pwd) || die "Could not connect: $DB +I::errstr\n"; my $query = $dbh->selectall_arrayref($sql, { Slice => {} }); foreach my $row (@$query) { $cache{$row->{phone}}{last} = $row->{last}; $cache{$row->{phone}}{first} = $row->{first}; $cache{$row->{phone}}{address} = $row->{address}; } bless $cache{$row->{phone}}; }

I want to take the cache from package One and load it to a hash in another (package Two) to avoid having to call package One repeatedly.

package Two; use One; $hash = &One::query(); %hash = %$hash;

What I have doesn't work. Since there is no return statement in subroutine One::data, the last evaluation will be returned in One::query. In this case, is it the WHOLE cache? I am trying to get the WHOLE cache into the hash in package Two. All alternatives are helpful. I am trying to find all alternatives to this problem. Thanks in advance!!