in reply to Shorten a list...
Here's a version that preserves the line order within the file while allowing out of order lines (for example, "Group 1" appears on the first and last line below) and making empty lines separating groups optional (for example, there are blank lines within the "Group 5" lines below):
Running the above program produces:use strict; use warnings; my %seen; print map { $seen{$_} > 1 ? $_ x $seen{$_} . "\n" : () } grep { not $seen{$_}++ } grep { !/^\s*$/ } <DATA>; __DATA__ Group 1 Group 2 Group 3 Group 3 Group 3 Group 4 Group 5 Group 5 Group 5 Group 5 Group 1
Group 1 Group 1 Group 3 Group 3 Group 3 Group 5 Group 5 Group 5 Group 5
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Shorten a list...
by la (Novice) on Oct 17, 2011 at 03:06 UTC | |
by Cristoforo (Curate) on Oct 17, 2011 at 21:30 UTC | |
by la (Novice) on Oct 17, 2011 at 21:51 UTC | |
by Cristoforo (Curate) on Oct 18, 2011 at 02:58 UTC | |
by la (Novice) on Oct 18, 2011 at 05:08 UTC | |
|