in reply to Variables as a variable name... (I know you shouldn't but...)
If so, then maybe something along the following (untested) lines might suffice ...
results in...use strict; use warnings; use Data::Dumper; my @results; while (<DATA>) { my @row = split; for (my $idx = 0; $idx < 3; $idx++) { push @{ $results[$idx] }, $row[$idx]; } } # Assume @results already populated... my ($day_of_week, $production_line, $output) = @results; my @data_to_plot; # Ignore the headers for (my $idx = 0; $idx < 3; $idx++) { shift @{ $results[$idx] } } ### # Extending an idea from [http://www.perl.com/doc/FAQs/FAQ/oldfaq-html +/Q5.4.html]... my %saw; my %production_lines = ( map { $_ => [] } grep ! $saw{$_}++, @$product +ion_line ); # ### for (my $index = 0; $index < @$day_of_week; $index++) { push @{ $data_to_plot[0] }, $day_of_week->[$index] unless grep /^$day_of_week->[$index]$/, @{ $data_to_plot[0] }; push @{ $production_lines{$production_line->[$index]} }, $output-> +[$index]; } push @data_to_plot, ( map { $production_lines{$_} } sort keys %product +ion_lines ); print Dumper \@data_to_plot; __DATA__ DayOfWeek ProductionLine Output 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 . .
!perl fred.pl $VAR1 = [ [ '2', '3', '4' ], [ '18353', '46775', '81302' ], [ '14878', '42601', '67542' ], [ '911', '1564', '1879' ] ];
Once more, sits back and awaits flames for bad code, style, karma etc...
Update:
Corrected typos
Tested - corrected 'features', added results
HTH ,
|
|---|