ChangeLog Merger
sort + uniq 機能つき。
#! /usr/bin/env perl use warnings; use strict; my @articles = (); # [id(date+author), begin, end] my @lines = <>; # collect ids and begins for my $i (0 .. $#lines) { if ( $lines[$i] =~ m/^(\d\d\d\d-\d\d-\d\d\s+.*)$/ ) { push @articles, [$1, $i, ]; } } # collect ends for my $i (0 .. $#articles-1) { $articles[$i][2] = $articles[$i+1][1]-1; } $articles[$#articles][2] = $#lines; # collect lines @articles = map [$_->[0], join('', @lines[ $_->[1]+1 .. $_->[2] ])], @articles; # uniq { my %h; foreach ( @articles ) { my $k = $_->[0]; if ( exists $h{$k} ) { $h{$k}->[1] .= $_->[1]; } else { $h{$k} = $_; } } @articles = values %h; } print map "$_->[0]\n$_->[1]", sort { - ($a->[0] cmp $b->[0]) } @articles;