in reply to Adding an element to an array
poj#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @all_profile; my %homes_by_names; while (<DATA>){ chomp; my @f = split ',',$_; my %profile; $profile{ NAME } = $f[0];#$row->{'name'}; $profile{ ADDRESS } = $f[1];#$row->{'address'}; $profile{ HOME } = $f[2];#$row->{'home'}; # I will need to count the how many homes here ++$homes_by_names{ $profile{ NAME } }; push @all_profile, \%profile; } for (@all_profile){ $_->{'HOME COUNT'} = $homes_by_names{ $_->{ NAME } }; } print Dumper \@all_profile; __DATA__ 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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Adding an element to an array
by Anonymous Monk on Oct 15, 2015 at 15:30 UTC | |
by NetWallah (Canon) on Oct 15, 2015 at 15:40 UTC | |
by Anonymous Monk on Oct 15, 2015 at 15:54 UTC | |
by poj (Abbot) on Oct 15, 2015 at 16:12 UTC | |
by Anonymous Monk on Oct 15, 2015 at 17:09 UTC | |
| |
|
Re^2: Adding an element to an array
by Anonymous Monk on Oct 14, 2015 at 19:43 UTC | |
by davido (Cardinal) on Oct 15, 2015 at 06:59 UTC | |
by poj (Abbot) on Oct 14, 2015 at 20:10 UTC | |
by Anonymous Monk on Oct 15, 2015 at 13:57 UTC | |
by sandeepb (Novice) on Oct 16, 2015 at 10:51 UTC |