User:Nsh/Sort-songs-script
Appearance
< User:Nsh
my $infile = "/tmp/songs"; ## infile is wiki text from page: en.wikipedia.org/wiki/Wikipedia:Sound/list open(IN,"<$infile"); $text = join("\n",<IN>); close IN; # read into one scalar my $header = $& if $text =~ s/^.*?\n\|\-\s*\n//s; # remove header my $footer = $& if $text =~ s/\|\}\W*?$//s; # remove footer my @entries = split(m#\n\|\-\s*\n#, $text); # split into each table entry for (@entries) { my @lines = split(m#\n\|#, $_); # split into each line my $comp = $lines[2]; $comp = $1 if $lines[2] =~ m#\[\[(.+?)\]\]#s; # remove [[ ]] from composer name push @{$composers{$comp}}, $_; # push this entry into the composers array } print $header; print join "\n|-\n", @{$composers{$_}} for sort keys %composers; # perl magick! print $footer;