in reply to Reading/Parsing an XML file using Perl

You can get a list of XML files in a directory using glob. Then, loop over those files and simply print the file name.
use strict; use warnings; use XML::Simple; my $path = '.'; # add your path here for my $xfile (glob "$path/*.xml") { print "xfile=$xfile\n"; my $xml = XML::Simple->new(); my $file = $xml->XMLin($xfile) or die $!; # do your checks... }

Replies are listed 'Best First'.
Re^2: Reading/Parsing an XML file using Perl
by manu_06 (Novice) on Sep 17, 2010 at 00:45 UTC
    Hi,

    Thank you for the help. I was trying your suggestion but it is showing up syntax error near the end of the script "}"

    #!/usr/local/bin/perl-w use strict; use warnings; use XML::Simple; my $path = 'C:\Documents and Settings\user\Desktop\output2\FITS\ IMD02 +5350802'; # add your path here for my $xfile (glob "$path/*.xml") { print "xfile=$xfile\n"; my $xml = XML::Simple->new(); my $file = $xml->XMLin($xfile) or die $!; if (($file->{identification}{'identity'}{'format'} eq 'JPEG File I +nterchange Format') && ($file->{filestatus}{'well-formed'}{'content'} eq 'true') && ($file->{ +filestatus}{'valid'}{'content'} eq 'true')) }

    Error: syntax error at one.pl line 14, near ") }"

      You're missing at least an opening brace. You have

      ($file->{filestatus}{'well-formed'}{'content'} eq 'true') && ($file->{ +filestatus}{'valid'}{'content'} eq 'true')) }

      but you need something like

      ($file->{filestatus}{'well-formed'}{'content'} eq 'true') && ($file->{ +filestatus}{'valid'}{'content'} eq 'true')) { # do something useful }