Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Perl / XML / Pattern Match

DZone's Guide to

Perl / XML / Pattern Match

·
Free Resource
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  at the very end of the file.


my $holdTerminator = $/;
undef $/;

if (open(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 '';

}
close(FILE1);

  
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}