User:Thnidu/anchor-alphas
Appearance
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
- (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
#!/usr/bin/perl # Sun., July 19, 6:51pm UTC # 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 [[List of people from Pennsylvania#Artists| "Artists" sublist]] of [[List of people from Pennsylvania]]. # Example input: # Actors AB CD EG HK LM NR SZ # # Output # # {{center|[[#ActorsAB|'''A–B''']] {{!}} [[#ActorsCD|'''C–D''']] {{!}} [[#ActorsEG|'''E–G''']] {{!}} [[#ActorsHK|'''H–K''']] {{!}} [[#ActorsLM|'''L–M''']] {{!}} [[#ActorsNR|'''N–R''']] {{!}} [[#ActorsSZ|'''S–Z''']]}} # # ;{{anchor|ActorsAB}} A–B # ;{{anchor|ActorsCD}} C–D # ;{{anchor|ActorsEG}} E–G # ;{{anchor|ActorsHK}} H–K # ;{{anchor|ActorsLM}} L–M # ;{{anchor|ActorsNR}} N–R # ;{{anchor|ActorsSZ}} S–Z # # The code lines commented out with "##" will print the input class and letter groups first, then a # separator line of equal signs. $class = shift; ## printf("%s\n", $class); while($letts = shift @ARGV) { push @letts, $letts; } ## foreach(@letts) { ## print "$_\t"; ## } ## print "\n"; ## print "=============\n"; $out = "{{center|"; foreach(@letts) { ($l1, $l2) = split('', $_,2); $out .= sprintf "[[#%s%s%s|'''%s–%s''']] {{!}} ", $class, $l1, $l2, $l1, $l2; } $out =~ s/ {{!}} $/}}/; print "\n", $out, "\n\n"; # sample output: # |[[#ActorsAB|'''A–B''']] {{!}} [[#ActorsCD|'''C–D''']] {{!}} [[#ActorsEG|'''E–G''']] {{!}} [[#ActorsHK|'''H–K''']] {{!}} [[#ActorsLM|'''L–M''']] {{!}} [[#ActorsNR|'''N–R''']] {{!}} [[#ActorsSZ|'''S–Z''']]}} foreach(@letts) { ($l1, $l2) = split('', $_,2); $out = sprintf ";{{anchor|%s%s%s}} %s–%s", $class, $l1, $l2, $l1, $l2; print $out, "\n"; } # sample output: # ;{{anchor|ActorsAB}} A–B print "\n";