in reply to how to make a foreach loop dynamic?
Looking at your code, here's what I have in mind as a solution
It might not be perfect:
#!/usr/bin/perl use strict; use warnings; # store everything in a hash where ( option = hash key ) my %HASH; while (<DATA>) { chomp; my @line = split /:/,$_; my $K = shift @line; my @V = split /,/ , shift @line; $HASH{$K} = \@V; } # options per line my $OPTIONS_PER_LINE = 3; foreach my $C (1..$OPTIONS_PER_LINE) { foreach my $i (sort keys %HASH) { print $HASH{$i}->[$C-1]; } print "\n"; } __DATA__ option1:apple,banana,orange option2:apple,banana,orange option3:pork,chicken,beef
|
|---|