in reply to Need Help With Syntax for (Complicated for Me) Data Structure
#!/usr/bin/perl use strict; use warnings; my %data; while (<DATA>) { chomp; my ($team, @field) = split; push @{ $data{$team} }, \@field; }
This creates a single hash entry for each team. The value is a reference to an array of all entries for that team. Each entry is an array reference to the specific stats for that entry.
Alternatively, you could do the HoHoA. Added implementation below.
#!/usr/bin/perl use strict; use warnings; use constant TEAM => 0; use constant POINTS => 1; use constant TALLIES => 2; use constant SCORES => 3; use constant METRICS => 4; my %data; while (<DATA>) { chomp; my @col = split; push @{ $data{$col[TEAM]}{POINTS} }, $col[POINTS]; push @{ $data{$col[TEAM]}{TALLIES} }, $col[TALLIES]; push @{ $data{$col[TEAM]}{SCORES} }, $col[SCORES]; push @{ $data{$col[TEAM]}{METRICS} }, $col[METRICS]; }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need Help With Syntax for (Complicated for Me) Data Structure
by o2bwise (Scribe) on Jan 30, 2007 at 02:10 UTC | |
|
Re^2: Need Help With Syntax for (Complicated for Me) Data Structure
by o2bwise (Scribe) on Jan 31, 2007 at 20:06 UTC | |
by Limbic~Region (Chancellor) on Jan 31, 2007 at 20:16 UTC |