Talk:Australian States and Territories/Australian states table generator
Appearance
This is the Perl script used to generate the tables for the 8 States and territories of Australia.
#!/usr/bin/perl # Table generator for Australian states # Licensed under GFDL, submitted to Wikipedia. # # This is a Perl script. To run it on a Windows platform, you need # to download a Windows Perl distribution such as ActivePerl # http://www.ActiveState.com/ActivePerl # # Usage: perl whatever_filename_you_gave_this_script.pl "Full name of state" # # e.g. perl gen.pl "Australian Capital Territory" # # Wikitext will appear on standard output, and unless you comment out the relevant # lines, it will be copied to the Windows clipboard also. # # This script consists of three sections: wikitext with substitution tags, a CSV # spreadsheet, and the Perl code to perform the substitution and output the result. # The CSV section can be edited with any spreadsheet application. use Text::ParseWords; # Optional clipboard dump: use Win32::Clipboard; #------------------------------------------------------------------------- $wikitext = <<'END OF WIKITEXT'; <table border="1" cellpadding="2" cellspacing="0" align="right" width="300px"> <caption><font size="+1"> '''<<Name>>''' </font></caption><tr><td style="background:#efefef;" align="center" colspan=2> <table border="0" cellpadding="2" cellspacing="0"> <tr><td align="center" width="140px"> [[Image:<<Flag>>|<<Name>> state flag]] </td><td align="center" width="140px"> [[Image::<<COA>>|<<Name>> coat of arms]] </td></tr><tr><td align="center" width="140px"><font size=-1> State flag ([[Flag of <<Name>>|Full size]]) </font></td><td align="center" width="140px"> <font size=-1>Coat of Arms ([[Coat of Arms of <<Name>>|Full size]])</font> </td></tr></table></td></tr><tr><td align="center" colspan=2> [[Image:<<Map>>|Location of <<Name>>]] </td></tr><tr><td> [[Capital]] </td><td> [[<<Capital article>>|<<Capital>>]] </td></tr><tr><td> [[Area]]<br> — Land <br> — Marine <br> — Total </td><td> <br> <<Land area>> [[square kilometer|km²]]<br> <<Marine area>> [[square kilometer|km²]] <br> <<Total area>> [[square kilometer|km²]] <br> </td></tr><tr><td> [[Population]] (2002)<br> [[Density]] </td><td> <<Population>><br> <<Density>>/km² </td></tr><tr><td> [[Time zone]] </td><td> <<Time zone>> </td></tr><tr><td> Highest point </td><td> <<Mountain>> (<<Height>> [[metre|m]]) </td></tr><tr><td> [[ISO 3166-2]] code: </td><td> <<ISO 3166-2>> </td></tr></table> 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]]—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]]—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]]—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]]—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]]—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; # optional: Win32::Clipboard()->Set($wikitext);