Hi, I have a Perl script which recursively reads .JPG files form directories and sub directories and process them by triggering an external application and generate a xml log file for each image and after that it is trying to reading these xml log files and check for certain errors . if error exists it generates the file name and type of error. In my below script the first part is working I mean it is reading image files and creating the log files but the second one reading these log files for errors is not working. Can I get help regarding this logic and the mistakes in the script. Newbie to Perl so tried to some extent but not knowing exactly how to combine these two logic.
use File::Find; use File::Path; use XML::Simple; use File::Basename; use strict; use warnings; use diagnostics; # Get the directory from the command line or use the default director +y $search = shift || '/home/files/Input_test1'; # Get an array of all subdirectories find sub { push @dirs, $File::Find::name if -d }, $search ; for $dir ( @dirs ) { # opendir $dh, $dir or do { warn "Cannot open '$dir' $!" ; next ; } +; opendir( DIR, "$dir" ) ; @files = grep( /\.jpg$/, readdir( DIR ) ) ; closedir( DIR ) ; (my $logdir = $dir)=~s|^\Q$search/\E||i; $logdir =~ s|/IMAGES$||i; $logdir = "/home/output/logs/$logdir/NEW"; mkdir $logdir; # Creating a log file with the same filename to generate the logs foreach $file ( @files ) { print "$dir/$file\n" ; $logfilename =$file; $logfilename =~s/\.jpg$/.xml/; print "$logdir/$logfilename"; @args = ("/usr/software/fits-0.4.2/fits.sh", "-i", "$dir/$file", +"/usr/software/fits-0.4.2/fits.sh", "-o", "$logdir/$logfilename"); system( @args ) == 0 or die "system @args failed: $?"; } my $outfile = "$logdir" open OUTF, "> $outfile" or die print " can't create logfile; $!"; my $xml = XML::Simple->new; foreach my $fileName ($logfilename) { my ($filename, $directories, $suffix) = fileparse($fileName); my $file = $xml->XMLin($fileName) or die "Failed for $fileName: $! \n"; my $format = $file->{identification}{'identity'}{'format'}; if ($format ne 'JPEG File Interchange Format') { print OUTF "$filename | Identity Format Error\n"; }
In reply to Help regarding a perl script by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |