jms53 has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
I have a module that gets information from a database, and has a sub that returns a hash.
if Dumper is used on %transactions in the module, the correct information is printed to the terminal, however, when I try to do this on a script, I get no output:
which output $VAR1={}
I have a module that gets information from a database, and has a sub that returns a hash.
sub get_transactions { my $transactions_id = shift; my $sql = <<EOSQL # the sql part works EOSQL my $ar = $dbh->selectall_arrayref( $sql, undef, $transactions_id ); my %transactions; for ( @$ar ) { my ($date, $type, $amount, $new_balance) = @$_; %{$transactions{$date}} = ('Date' => $date, 'Type' => $type, 'Amou +nt' => $amount, 'Ending_balance' => $new_balance); } return %transactions; }
if Dumper is used on %transactions in the module, the correct information is printed to the terminal, however, when I try to do this on a script, I get no output:
which outputs nothing.I have tried using references,my %transac = MyDB->get_transactions( 10000); print Dumper %transac;
#Module: ... return \%transactions; #script my $transac = MyDB->get_transactions( 10000); print Dumper $transac;
which output $VAR1={}
I've managed to point the problem to how I'm calling the sub, but haven't managed tog et it to work as expected.
Thank you,
J -
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: returning a hash from a module
by choroba (Cardinal) on Feb 28, 2013 at 20:47 UTC | |
by jms53 (Monk) on Mar 01, 2013 at 19:13 UTC | |
Re: returning a hash from a module
by blue_cowdawg (Monsignor) on Feb 28, 2013 at 20:18 UTC | |
Re: returning a hash from a module
by kcott (Archbishop) on Feb 28, 2013 at 21:47 UTC | |
by jms53 (Monk) on Mar 01, 2013 at 19:09 UTC | |
Re: returning a hash from a module
by sundialsvc4 (Abbot) on Mar 01, 2013 at 04:58 UTC | |
by Lotus1 (Vicar) on Mar 07, 2013 at 19:24 UTC |
Back to
Seekers of Perl Wisdom