http://qs321.pair.com?node_id=1082770


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; }