Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Returning a hash and looping on the results.

by Anonymous Monk
on Apr 18, 2014 at 15:22 UTC ( #1082781=note: print w/replies, xml ) Need Help??


in reply to Re^2: Returning a hash and looping on the results.
in thread Returning a hash and looping on the results.

OK, this I found to be the better way of doing it:

my $result = data(); foreach my $res (@$result) { my $name = $res->{'username'}; my $city = $res->{'city'}; print "User Name = $name - City: $city\n"; } my @all_data = (); sub data { ... db code stuff ... my %no_name_found; if(@$sql) { for(my $i = 0; $i < @$sql; $i++) { my $user_name = $sql->[$i]{'username'} || ''; my $city = $sql->[$i]{'city'} || ''; # verify user name, this name will come back from this sub check_ +name my $no_name = check_name ( user => $user_name, ); #Get a new hash for the data my %data; $data{username} = $user_name; $data{city} = $city; push @all_data, \%data; } } return \@all_data; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082781]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2021-01-17 06:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?