Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

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


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

Yes, I'm sorry!
  • Comment on Re^2: Returning a hash and looping on the results.

Replies are listed 'Best First'.
Re^3: Returning a hash and looping on the results.
by kennethk (Abbot) on Apr 18, 2014 at 14:40 UTC

    Problems like this can be avoided with the strict pragma. See Use strict warnings and diagnostics or die for a more thorough discussion.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re^3: Returning a hash and looping on the results.
by Anonymous Monk on Apr 18, 2014 at 15:22 UTC
    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://1082770]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2021-01-20 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?