c4onastick has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks,
I've got some data in tab-separated values that comes in the form:
I'd like to get that in to either a hash or an array by reading the file in from STDIN. I need to be able to query the data asking things like, "What's Data Set 1's y value at Data Set 3's x3 value?" Wherein lies the problem, I need to keep the "Data Set" labels associated with the data. I started writing it like this:
So my question is: what would be the appropriate complex internal data structure to parse the data into (I was going with a hash of hashes, maybe a hash of arrays?) I should mention that the reason I have this problem is that Data Set 1's x1 does not necessarily equal Data Set 2's x1.
I've looked at Data::Table, and for the analysis that I need to do on the data, it doesn't quite seem to fit my needs.
Thanks in advance for your wisdom.
I've got some data in tab-separated values that comes in the form:
Data Set 1 | Data Set 2 | Data Set 3 | |||
X units | Y units | X units | Y units | X units | Y units |
x1 | y1 | x1 | y1 | x1 | y1 |
x2 | y2 | x2 | y2 | x2 | y2 |
x3 | y3 | x3 | y3 | x3 | y3 |
... | ... | ... | ... | ... | ... |
use warnings; my %data_sets; while(<>){ # I did the $line thing because there's some garbage at the top of +the file that I don't want my $line++; if($line == 2){ while(/\G([^\t]+)/g){ $data_sets{$_} = {}; } } if($line > 3){ $data_sets{}; #<- ran into the problem right here! The script do +esn't know what data set its on! }
So my question is: what would be the appropriate complex internal data structure to parse the data into (I was going with a hash of hashes, maybe a hash of arrays?) I should mention that the reason I have this problem is that Data Set 1's x1 does not necessarily equal Data Set 2's x1.
I've looked at Data::Table, and for the analysis that I need to do on the data, it doesn't quite seem to fit my needs.
Thanks in advance for your wisdom.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help munging tabular data
by BrowserUk (Patriarch) on Aug 02, 2007 at 00:13 UTC | |
Re: Help munging tabular data
by GrandFather (Saint) on Aug 02, 2007 at 00:58 UTC | |
by aquarium (Curate) on Aug 02, 2007 at 04:21 UTC | |
Re: Help munging tabular data
by aquarium (Curate) on Aug 02, 2007 at 00:13 UTC | |
Re: Help munging tabular data
by Cristoforo (Curate) on Aug 04, 2007 at 03:42 UTC |
Back to
Seekers of Perl Wisdom