in reply to Need Help With Syntax for (Complicated for Me) Data Structure

o2bwise,
It seems like what you want is actually a HoAoA.
#!/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
    Thank you. I got pulled in quite a few directions, but I have saved youyr code and will study it. It sure looks nice and succinct!

    Tony
Re^2: Need Help With Syntax for (Complicated for Me) Data Structure
by o2bwise (Scribe) on Jan 31, 2007 at 20:06 UTC
    Hi,

    I just want to say that perhaps the biggest thing I learned was the need to surround the array with braces. I never noticed that before! And I saw it in all three replies to my post.

    I am wondering if you know any reference that discusses this syntax.

    Thanks again,

    Tony