Jump to content

User:Bmearns/userbox conv.pl

From Wikipedia, the free encyclopedia

This is a real simple script I used to subst that huge list of user boxes on /About me. It's real simple and straight forward; just copy paste your list of user boxes (should work with tables, too) into a file called "userboxes.txt", then run the perl script, and it'll write to a file called "converted_userboxes.txt". It'll actually work for all templates, it just uses a simple regex to match the template pattern (only once per line!) and then rewrites it including the subst, and including some fancy-schmany comments to help delineat between the different templates once they're subst'd. If you want to see what it looks like, look at the code for User:Bmearns/About me.


open (fid, "<userboxes.txt");
open (fwid, ">converted_userboxes.txt");
while ($record = <fid>) {
	if ($record =~ /([^{]*){{([^}]*)}}(.*)/){
		printf fwid "<!-- ------------------------------------------------\n !   {{subst:".$2."}}\n ! ---------------------------------------------- -->\n".$1."{{subst:".$2."}}".$3."\n<!-- **************END \"".$1."\"************* -->\n";
	}else{
		printf fwid $record;
	}
}

close(fid);
close(fwid);