Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How would I group the lines using BOTH name & date as "key", i.e. the output would be:nick 20/5/1950 one john 18/2/1980 two nick 19/6/1978 three nick 20/5/1950 four nick 12/9/2000 five john 15/6/1997 six nick 20/5/1950 seven
nick 20/5/1950 one four seven john 18/2/1980 two nick 19/6/1978 three nick 12/9/2000 five john 15/6/1997 six
use strict; use warnings; my %res; while (<>) { my ( $name, $rest ) = split /\t/; push @{ $res{$name} }, $rest; } for ( sort keys %res ) { print "$_ ", join( "|", @{ $res{$_} } ), "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: which data structure do I need for this grouping problem?
by 1nickt (Canon) on Sep 04, 2018 at 14:32 UTC | |
by bliako (Abbot) on Sep 04, 2018 at 20:15 UTC | |
|
Re: which data structure do I need for this grouping problem?
by haukex (Archbishop) on Sep 04, 2018 at 13:53 UTC | |
by Anonymous Monk on Sep 04, 2018 at 20:49 UTC | |
by Anonymous Monk on Sep 04, 2018 at 14:03 UTC | |
|
Re: which data structure do I need for this grouping problem?
by kevbot (Vicar) on Sep 05, 2018 at 04:41 UTC | |
|
Re: which data structure do I need for this grouping problem?
by afoken (Chancellor) on Sep 05, 2018 at 17:20 UTC |