Hi Monks!
I am trying to count how many "houses" each person has once I get the data from the database, I included
a data sample so you can see better what I am trying to do.
I tried the way I have in this sample code here but it isn’t working.
Any suggestions on how I could do this?
Sample code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
...
my @all_profile;
my %homes_by_names;
foreach my $row ( @{ $sql } ) {
my %profile;
$profile{ NAME } = $row->{'name'};
$profile{ ADDRESS } = $row->{'address'};
$profile{ HOME } = $row->{'home'};
# I will need to count the how many homes here
push ( @{ $homes_by_names{$profile{ HOME } } }, \%profile);
push @all_profile, { 'HOME COUNT' => scalar @{ $homes_by_names{HO
+ME} };
push @all_profile, \%profile;
}
print Dumper \@all_profile;
$VAR1 = [
{
'NAME' => 'John Doe',
'ADDRESS' => 'Main Street',
'HOME' => 'House 1',
'HOME COUNT' => '3',
},
...
=data
# Sample data to show how I need to count how many Houses per person
John Doe, Main Street, House 1
John Doe, Main Street, House 1
John Doe, Main Street, House 1
Mary Lou, Central Street, House 1
Mary Lou, Central Street, House 1
Mary Lou, Central Street, House 1
Mary Lou, Central Street, House 1
Jane B,. Squere Rd., House 1
Maria D., Pat street, House B
Maria D., Pat street, House B
Thanks for looking!!!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.