#!/usr/bin/perl use strict; use warnings; my @order = qw( Using Options Pragmas Extensions Differences Internals ); my %h; my %s; foreach my $fn (@ARGV) { open my $fh, "<$fn" or die "$!: could not open $fn"; while(<$fh>) { /^(\{\-|\/\*)[#@](\w+)(\s+(\d+))?\s*$/ or next; my ($section,$text,$order) = ($2,"",defined $4 ? $4 : 100); while(<$fh>) { /^(\-\}|\*\/)\s*$/ and last; $text .= $_; } $s{$section} ||= []; push @{$s{$section} ||= []}, [$order,$text]; $h{$section}{files} .= ":$fn"; } } foreach (keys %s) { $h{$_}{text} = join "\n",map { $_->[1] } sort { $a->[0] <=> $b->[0] } @{$s{$_}}; } foreach(@order) { print "\n# $_\n\n"; $h{$_}{text} =~ s/^(#+ )/#$1/mg; print $h{$_}{text}; } foreach(keys %h) { print STDERR $_," ",$h{$_}{files},"\n"; }