Talk:Australian States and Territories/Australian states table generator

This is the Perl script used to generate the tables for the 8 States and territories of Australia.


 * 1) !/usr/bin/perl


 * 1) Table generator for Australian states
 * 2) Licensed under GFDL, submitted to Wikipedia.
 * 3) This is a Perl script. To run it on a Windows platform, you need
 * 4) to download a Windows Perl distribution such as ActivePerl
 * 5) http://www.ActiveState.com/ActivePerl
 * 6) Usage: perl whatever_filename_you_gave_this_script.pl "Full name of state"
 * 7) e.g. perl gen.pl "Australian Capital Territory"
 * 8) Wikitext will appear on standard output, and unless you comment out the relevant
 * 9) lines, it will be copied to the Windows clipboard also.
 * 10) This script consists of three sections: wikitext with substitution tags, a CSV
 * 11) spreadsheet, and the Perl code to perform the substitution and output the result.
 * 12) The CSV section can be edited with any spreadsheet application.
 * 1) lines, it will be copied to the Windows clipboard also.
 * 2) This script consists of three sections: wikitext with substitution tags, a CSV
 * 3) spreadsheet, and the Perl code to perform the substitution and output the result.
 * 4) The CSV section can be edited with any spreadsheet application.
 * 1) The CSV section can be edited with any spreadsheet application.

use Text::ParseWords;

use Win32::Clipboard;
 * 1) Optional clipboard dump:

$wikitext = <<'END OF WIKITEXT';  Capital <> Area &mdash; Land &mdash; Marine &mdash; Total <> km² <> km² <> km² Population (2002) Density <> <>/km² Time zone <> Highest point <> (<> m) ISO 3166-2 code: <> END OF WIKITEXT



$csv = <<'END OF CSV SPREADSHEET'; Name,Flag,COA,Big flag,Big COA,,Capital,Capital article,Mainland area,Island area,Land area,Marine area,Total,Population,Density,Mainland coastal length,Island,Total length,ISO 3166-2,Mountain,Height,Time zone Australian Capital Territory,Australian_Capital_Territory_flag_small.jpg,Canberra_coat_of_arms_small.jpg,Australian_Capital_Territory_flag.jpg,Canberra_coat_of_arms.jpg,ACT_in_Australia_map.png,Canberra,Canberra, 2 358, 0, 2 358,  0, 2 358, 322 200,136.64,  54,  3,  57,AU-CT,Bimberi Peak,1912,UTC+10 (except during daylight saving time&mdash;UTC+11) New South Wales,New_South_Wales_flag_small.png,New_South_Wales_coat_of_arms_small.jpg,,New_South_Wales_coat_of_arms.png,NSW_in_Australia_map.png,Canberra,Canberra, 800 628, 14, 800 642, 8 802, 809 444,6 657 400,8.32, 2 007,  130, 2 137,AU-NS,Mt Kosciuszko,2228,UTC+10 (except during daylight saving time&mdash;UTC+11) Northern Territory,Northern_Territory_flag_small.png,Northern_Territory_crest_small.jpg,Northern_Territory_flag.png,Northern_Territory_crest.jpg,NT_in_Australia_map.png,Sydney,Sydney,1 335 742, 13 387,1 349 129, 71 839,1 420 968, 197 700,0.15, 5 437, 5 516, 10 953,AU-NT,Mt Zeil,1531,UTC+9:30 Queensland,Queensland_flag_small.png,Queensland_coat_of_arms_small.jpg,,,QLD_in_Australia_map.png,Darwin,"Darwin, Australia",1 723 936, 6 712,1 730 648, 121 994,1 852 642,3 729 000,2.15, 6 973, 6 374, 13 347,AU-QL,Bartle Frere (South Peak),1622,UTC+10 South Australia,South_Australia_flag_small.png,South_Australia_coat_of_arms_small.jpg,South_Australia_flag.png,South_Australia_coat_of_arms.jpg,SA_in_Australia_map.png,Brisbane,Brisbane, 978 810, 4 672, 983 482, 60 032,1 043 514,1 522 500,1.55, 3 816, 1 251, 5 067,AU-SA,Mt Woodroffe,1435,UTC+9:30 (except during daylight saving time&mdash;UTC+10:30) Tasmania,Tasmania_flag_small.png,Tasmania_coat_of_arms_small.jpg,Tasmania_flag.png,Tasmania_coat_of_arms.jpg,TAS_in_Australia_map.png,Adelaide,Adelaide, 64 519, 3 882, 68 401, 22 357, 90 758, 473 400,6.92, 2 833, 2 049, 4 882,AU-TS,Mt Ossa,1617,UTC+10 (except during daylight saving time&mdash;UTC+11) Victoria,Victoria_state_flag_small.png,Victoria_state_armorial_ensign_small.jpg,,,VIC_in_Australia_map.png,Hobart,"Hobart, Australia", 227 010, 406, 227 416, 10 213, 237 629,4 888 200,21.49, 1 868,  644, 2 512,AU-VI,Mt Bogong,1986,UTC+10 (except during daylight saving time&mdash;UTC+11) Western Australia,Western_Australia_flag_small.png,Western_Australia_coat_of_arms_small.jpg,Western_Australia_flag.png,Western_Australia_coat_of_arms.jpg,WA_in_Australia_map.png,Melbourne,Melbourne,2 526 786, 3 089,2 529 875, 115 740,2 645 615,1 934 500,0.76, 12 889, 7 892, 20 781,AU-WA,Mt Meharry,1253,UTC+8 END OF CSV SPREADSHEET

$stateName = shift; @lines = split('\n', $csv); @heads = parse_line(',', 0, $lines[0]);

foreach $line (@lines) { @cells = parse_line(',', 0, $line); if ($cells[0] eq $stateName) { for ($col=0; $col < scalar(@cells); $col++) { $wikitext =~ s/<<$heads[$col]>>/$cells[$col]/g; }	} }

print $wikitext;

Win32::Clipboard->Set($wikitext);
 * 1) optional: