Greetings Monks,
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 |
| ... | ... | ... | ... | ... | ... |
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:
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.