Hi, pretty simple question here for the experts. I'm running a .csv list through a foreach loop, and if certain criteria is met, I want to print it out but separated by categories:
@data = <IN>; my @sorted_data = sort @data; foreach $line (@sorted_data) { chomp $line; $line =~ /(.*?)\,(.*?)\,(.*)/; $first = $1; $second = $2; $last = $3; if ($last eq $second) { if($second eq $first) { $print "$second really = $first\n"; } else { print "$last only = $first\n"; } } }
Instead of doing the print line by line, I'd like to get out of the foreach to print everything separately - like all the $second = $first together and the $last = $first together. Current output has them all mixed up since I'm looking at it line by line and printing the same. Would hash be better? sub? Would appreciate any assistance.
In reply to Printing Array Output Outisde foreach by ahjohnson2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |