Aug 9, 2017, 2:01 PM
Post #2 of 3
Re: [BoJo] How to extract sub strings?
[In reply to]
ALWAYS use strict. In this case, it would have found one of your errors.
Every statement must end in a semicolon. This is not exactly true, but its not worth worrying about the exceptions because it never hurts.
The function 'system' is not the same as backticks. You need the backticks in both places.
The first argument of split is a regex, not a string.
The variable that you call $dtg is an array, not a scalar. It must be declared @dtg.
I expect that your script will work with these changes.
Although it 'works', it is a poor practice to declare all your variables at the start of the script.
It is very bad practice to use system or backticks when a perl solution is available. In your case, you should use the perl module Image::ExifTool rather than the shell utility.
Update: Added corrected code (untested).
my $picnames= `exiftool pic-0.jpg |grep 'Region Name'`;
my $createdtg=`exiftool pic-0.jpg | grep 'Create Date'`;
my @dtg=split(/ /, $createdtg);
print $dtg ;
(This post was edited by BillKSmith on Aug 9, 2017, 2:32 PM)