#!/usr/bin/perl # read lynx -dump output, write link references # before line they refer to. # # Example: # [21]Ars Technica # ... # [22]CamWorld # ... # References # 21. http://www.arstechnica.com/ # 22. http://www.camworld.com/ # # is turned into # http://www.arstechnica.com/ # Ars Technica # ... # http://www.camworld.com/ # CamWorld # ... chomp (@lines = <>); # # Find references, then store links. # $found = 0; foreach (@lines) { $found++ if /^References$/; if ($found) { s/^\s*//g; s/\s*$//g; if (/^[0-9]/) { ($num, $dest) = split; $num =~ s/\.//; $links{$num} = $dest; } } } # # Go through start of article, find links, insert destinations. # foreach (@lines) { last if /^References$/; while (/\[([0-9]+)\]/) { print "$links{$1}\n"; s/\[[0-9]+\]//; } print "$_\n"; } exit (0);