in reply to join column 3 for unique values
I'd stash everything into a data structure (HoHoA, ie. hash of hashes of arrays), which makes sure everything gets aggregated properly, then print it out.
use warnings; use strict; my %hash; while (<DATA>){ chomp; my ($key, $val, $colour) = split; push @{ $hash{$key}{$val} }, $colour; } for my $k (keys %hash){ for (keys %{ $hash{$k} }){ my $colours = join ':', @{ $hash{$k}{$_} }; print "$k $_ $colours\n"; } } __DATA__ A1 abc yellow B1 xyz green A2 cde red A1 abc green A2 cde yellow A1 abc blue
Output:
A1 abc yellow:green:blue A2 cde red:yellow B1 xyz green
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: join column 3 for unique values
by hello_beginner (Novice) on Sep 05, 2016 at 15:04 UTC | |
by stevieb (Canon) on Sep 05, 2016 at 15:30 UTC |