User:Thnidu/anchor-alphas

Written to use on List of people from Pennsylvania.

Produce subsection header and anchor labels to paste into a long alphabetical list to divide it into alphabetical sections, e.g., A-F, G-M, N-P, Q-Z. For use in articles with very long lists that are already subdivided by category. The examples here are from the "Artists" sublist of List of people from Pennsylvania.

Example input: Actors AB CD EG HK LM NR SZ

Output

A–B
 * (clicking on any of the ranges above will take you to the header below)


 * A–B
 * C–D
 * E–G
 * H–K
 * L–M
 * N–R
 * S–Z


 * 1) !/usr/bin/perl
 * 2) Sun., July 19, 6:51pm UTC
 * 3) Produce subsection header and anchor labels to paste into a long alphabetical list to divide it
 * 4) into alphabetical sections, e.g., A-F, G-M, N-P, Q-Z.
 * 5) For use in articles with very long lists that are already subdivided by category.
 * 6) The examples here are from the  "Artists" sublist of List of people from Pennsylvania.
 * 7) Example input:
 * 8) Actors AB CD EG HK LM NR SZ
 * 9) Output
 * 10) A–B
 * 11) ; A–B
 * 12) ; C–D
 * 13) ; E–G
 * 14) ; H–K
 * 15) ; L–M
 * 16) ; N–R
 * 17) ; S–Z
 * 18) The code lines commented out with "##" will print the input class and letter groups first, then a
 * 19) separator line of equal signs.
 * 1) ; S–Z
 * 2) The code lines commented out with "##" will print the input class and letter groups first, then a
 * 3) separator line of equal signs.
 * 1) separator line of equal signs.

$class = shift;
 * 1) printf("%s\n", $class);

while($letts = shift @ARGV) { push @letts, $letts; }


 * 1) foreach(@letts) {
 * 2)     print "$_\t";
 * }
 * 1) print "\n";
 * 2) print "=============\n";

$out = ""; foreach(@letts) { ($l1, $l2) = split('', $_,2); $out .= sprintf "%s–%s/; print "\n", $out, "\n\n";


 * 1) sample output:
 * |A–B | C–D | E–G | H–K | L–M | N–R | S–Z}}

foreach(@letts) { ($l1, $l2) = split('', $_,2); $out = sprintf "; %s–%s", $class, $l1, $l2, $l1, $l2; print $out, "\n"; }


 * 1) sample output:
 * 2) ; A–B

print "\n";