Hashes are a good way to have what you want. The data you show can be easily collected into a multi-layer hash, with ProductionLine as the top-level key, DayOfWeek as the second-level key, and Output as the value. (You can flip the top- and second-layer keys if it is more convenient to think of the data that way; I like the ProductionLine at the top, especially if you are going to end up plotting based on Line).
The code snippet below should get you started.
You should also have a look at perldsc and perlreftut for some basic training in complex data structures in Perl.
use strict;
use warnings;
use Data::Dumper;
my %outputs;
while ( <DATA> ) {
my($day, $line, $output) = (split);
$outputs{$line}{$day} = $output;
}
print Dumper(\%outputs);
__END__
2 CANNING 18353
2 MULTIPACK 14878
2 QUEST 911
3 CANNING 46775
3 MULTIPACK 42601
3 QUEST 1564
4 CANNING 81302
4 MULTIPACK 67542
4 QUEST 1879
Output:
$VAR1 = {
'CANNING' => {
'4' => '81302',
'3' => '46775',
'2' => '18353'
},
'QUEST' => {
'4' => '1879',
'3' => '1564',
'2' => '911'
},
'MULTIPACK' => {
'4' => '67542',
'3' => '42601',
'2' => '14878'
}
};
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.