package main; use warnings; use strict; use Template; use MyDataParser; # get the filename from the console my $file = shift @ARGV || die "Error. You must specify a filename.\n"; # get the data from our file parser print "parsing $file\n"; my $records = MyDataParser->new( file => $file )->parse; # template for XML output # use Template::Plugin::XML::Escape to ensure valid XML my $ixemel = q[ [% USE XML.Escape %] [% record.it %] [% record.date.strftime('%y%m%d') %] [% record.tdate.strftime('%A, %B %d, %Y') %] [% record.edition %] [% record.tag %] [% record.body | xml_escape %] ]; # iterate the records for my $record ( @$records ) { # create a template object my $tt = Template->new(); # and process it( process->(template, data, filename) ); print "writing ", $record->tag, "\n"; die $tt->error(), "\n" unless $tt->process( \$ixemel, {record=>$record}, $record->tag ); } print "done\n";