Hi everyone,
Embarrassing question from a rookie. What is the best / correct way to call ExifTool within a larger perl script?
use Image::ExifTool;
loads the module. So far, so good. :)
my $info = $exifTool->ImageInfo( $filename );
gets the info from a file and puts it in a hash.
When I do this in a loop over several files, I call
undef $info; # done with the file
when I'm done so that I start (presumably) with a fresh hash every time. I then call
$info = $exifTool->ImageInfo( $filename ); # get the information for the next file
and so on.
But what does my $exifTool = new Image::ExifTool;
do?
Can I call it once at the beginning of the script, as in
use Image::ExifTool
my $exifTool = new Image::ExifTool;
and leave it alone for multiple files? Should I call undef $exifTool
before each new file as I do with $info??
On a related note, I have legacy shell snippets that I am gradually converting to perl. For now, I have calls such as
my @dataOfInterest = `exiftool ...`;
which feels like a terrible idea. Should I use -StayOpen or the @_ option? Or will the fact that I'm calling the shell from Perl mess things up?
Thank you for any insights and recommendations.
Paul
Hi Paul,
You should only create one Image::ExifTool object, and use it for all the files you want to read.
And you don't need to delete the old $info -- you can let the Perl garbage collection handle that.
If your shell scripts are calling exiftool repeatedly, then you may speed them up by using -stay_open, but it will be a lot of work, and probably easier to convert to using Perl and the API instead.
- Phil
Hi Phil,
Perfect! I'll lean out my Perl scripts and convert shell scripts to Perl.
Thank you so much for an amazing tool and the ongoing support.
Paul