User:Kroocsiogsi/Hero role formatting script

Instructions

 * 1) Install perl
 * 2) Put the perl script in the same folder as npc_heroes.txt (original is located in /dota/scripts/npc/npc_heroes.txt)
 * 3) Run the perl script from the command line
 * 4) Updates to the script may be necessary, especially to the "fix some hero names" section

Script
opendir(DIR, ".") or die "can't opendir $dirname: $!";
 * 1) open directory containing script and npc_heroes.txt

open(F1, ".\\npc_heroes.txt"); open(F2, ">.\\Template_Hero_role.txt");
 * 1) open original npc_heroes.txt
 * 1) open new file to become

local $/=undef; $filecontents = ;
 * 1) read npc_heroes.txt into a string

$filecontents =~ s/.*?npc_dota_hero_(\w+)(?:(?!npc_dota_hero).)*\"Role\"\s+\"(.*?)\"(?:(?!npc_dota_hero).)*/| $1 = \n/sg; $filecontents =~ s/,/}} \/ {{role|/g; $filecontents =~ s/LaneSupport/Lane Support/g;
 * 1) extract just the hero names and roles

$filecontents =~ s/_/ /g; $filecontents =~ s/ancient/ancient apparition/; $filecontents =~ s/antimage/anti-mage/; $filecontents =~ s/centaur/centaur_warrunner/; $filecontents =~ s/doom bringer/doom/; $filecontents =~ s/furion/nature's prophet/; $filecontents =~ s/life stealer/lifestealer/; $filecontents =~ s/magnataur/magnus/; $filecontents =~ s/necrolyte/necrophos/; $filecontents =~ s/nevermore/shadow fiend/; $filecontents =~ s/obsidian destroyer/outworld devourer/; $filecontents =~ s/queenofpain/queen of pain/; $filecontents =~ s/rattletrap/clockwerk/; $filecontents =~ s/shredder/timbersaw/; $filecontents =~ s/treant/treant protector/; $filecontents =~ s/vengefulspirit/vengeful spirit/; $filecontents =~ s/windrunner/windranger/; $filecontents =~ s/wisp/io/; $filecontents =~ s/skeleton_king/wraith_king/; $filecontents =~ s/zuus/zeus/; $filecontents =~ s/\| nature's prophet/| nature&#39;s prophet \n| nature's prophet/;
 * 1) fix some hero names

@filecontents = split("\n",$filecontents); @sorted_filecontents = sort @filecontents; $filecontents = join("\n",@sorted_filecontents);
 * 1) alphabetize the list

print F2 " {{#switch:{{lc:{{{1|}}}}}\n"; print F2 $filecontents; print F2 "\n| #default = N/A\n}} * Returns the official (default in-game) roles for heroes\n* {{tlx|Hero role|Anti-Mage}} generates \"Carry / Escape\".\n* {{tlx|Hero role|Jakiro}} generates \"Nuker / Pusher / Lane Support / Disabler\".\n\n\'\'This template can be generated by User:Kroocsiogsi/Hero role formatting script‎ if you don't feel like manually updating it.\'\'\n\n\n ";
 * 1) print the beginning of
 * 1) print the hero role lines
 * 1) print the end of {{Template:Hero_role}}

close(F1); close(F2);
 * 1) close npc_heroes.txt
 * 1) close {{Template:Hero_role}}

closedir(DIR);
 * 1) close directory