This uses two HoHoA - one for the X coordinate data and another for the Y coordinate data. Or you could store the coordinates in a data structure:my $DATA_X; my $DATA_Y; while (<>) { my ($obs, $det, $x, $y) = split(' ', $_); push(@{$DATA_X->{$obs}->{$det}}, $x); push(@{$DATA_Y->{$obs}->{$det}}, $y); }
And here's how to access the data (using the second approach):my $DATA; while (<>) { my ($obs, $det, $x, $y) = split(' ', $_); push(@{$DATA->{$obs}->{$det}}, {x => $x, y => $y}); }
Whether or not this is the best data structure for your data depends on what you want to do with it.print $DATA->{21}->{'DET-2'}->[0]->{x}; # prints 896.657564735788 print $DATA->{47}->{'DET-7'}->[1]->{y}; # prints 519.649226713148
In reply to Re: structuring data: aka walk first, grok later
by pc88mxer
in thread structuring data: aka walk first, grok later
by chexmix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |