(c/p from excel sheet)
Given that, you may want to consider Spreadsheet::ParseExcel to read the data in directly from your Excel spreadsheet.
Edit: Thanks to the OP for helping me understand the requirements. I now believe this will be much more in line with what you're after:
my (undef, @col) = split /\t/, <>; # Column names my %prob_map; while (my ($from, @values) = split /\t/, <>) { @{$prob_map{$from}}{@col} = @values; } say "AAC to AAA = " . $prob_map{AAC}{AAA}; say "AAA to AAC = " . $prob_map{AAA}{AAC}; __END__ AAC to AAA = 0.011 AAA to AAC = 0.01506
Previous line-based (i.e., row major) suggestion is below.
Otherwise, parsing the plain text you've provided is fairly straightforward as well:
my @col = split /\t/, <>; # Column headings my @lines = map { my %l; @l{@col} = split /\t/; \%l } <>;
However, whether that's actually an improvement on your code or not is debatable. :-)
In reply to Re: Best way to read in an XbyX table into a Hash{Key}{Key2}[value] structure
by rjt
in thread Best way to read in an XbyX table into a Hash{Key}{Key2}[value] structure
by ZWcarp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |