Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Perl / XML / Pattern Match

This code parses through the games.xml file generated by EMUCenter and changes Genre to Letter, also taking the first letter of the Title property and adding it to the Letter property. This allows sorting by letter in the EMUCenter interface. Two things, Change the metadata entry from Genre to Letter and remove the trailing </game> at the very end of the file.

my $holdTerminator = $/;
undef $/;

if (open(FILE, '<c:\games.xml')) {
	$file = <FILE>;
}
$/ = $holdTerminator;

@array = split /\<\/game\>/, $file;
open(FILE1, '>c:\newgames.xml');

foreach $line (@array){
	$line =~
s/(\n\s+.*?"Title">)(.)(.*?)"Genre">.*?(<\/property>)/$1$2$3"Letter">$2$4/is
;
	print FILE1 $line;
	print FILE1 '</game>';

}
close(FILE1);
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS