Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks for looking!sub names{ ... my @loop_data = (); # initialize an array while ( my $row = $data_handle->fetchrow_hashref ){ my %row_data; # get a fresh hash for the row data # fill in this row $row_data{names} = $row->{'names'} || ''; # push a reference to this row into the loop! push(@loop_data, \%row_data); } my %final_data; if(!@loop_data) { push @loop_data, {names => 'No names'}; %final_data = @loop_data; return \%final_data; }else { %final_data = @loop_data; return \%final_data; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Returning hash reference from a sub
by blue_cowdawg (Monsignor) on Mar 18, 2013 at 14:37 UTC | |
|
Re: Returning hash reference from a sub
by tobias_hofer (Friar) on Mar 18, 2013 at 13:47 UTC | |
by Anonymous Monk on Mar 18, 2013 at 13:57 UTC | |
by Corion (Patriarch) on Mar 18, 2013 at 13:59 UTC | |
by tobias_hofer (Friar) on Mar 18, 2013 at 14:10 UTC | |
by Anonymous Monk on Mar 18, 2013 at 14:08 UTC | |
by Corion (Patriarch) on Mar 18, 2013 at 14:13 UTC | |
by tobias_hofer (Friar) on Mar 18, 2013 at 14:13 UTC | |
|