ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: Charlie D. on May 02, 2022, 11:47:34 AM

Title: Perl Regexp string comparison operators (IF /i modifier) does not work anymore
Post by: Charlie D. on May 02, 2022, 11:47:34 AM
Hello,

I Think I found a bug in the Perl -if /<search string>/i functionality in the latest version of ExifTool 12.41 (April 7, 2022).

In my arguments-file:
# This one works.
-IF
$Model eq 'Canon EOS 80D' or $Model eq 'TG-4' or $Model eq 'iPhone 7'
# The case-insensitive one doesn't work anymore.
-IF
$CreatorWorkEmail !~ /my\@e-mail.address/i

Command line: ExifTool -@ <path and name of my arguments-file> <path to (and name of) imagefiles>

In the command line (I'm using Windows 10) the results are the same:

I tried to look the settings up at the old forum, in case I made a mistake. But that site doesn't exist anymore ::) so, see its snapshot made in the WayBackMachine https://web.archive.org/web/20130817130051/http://cpanforum.com/threads/8294
Perl's Regexp /i (case-insensitive pattern matching) moderator is explained here: https://perldoc.perl.org/perlop#Regexp-Quote-Like-Operators

When I use an older ExifTool version 12.40(?) (February 8, 2022) the -if /<search string>/i functions as expected.
Is this a bug or is something else changed?

Thanks in advance!
Charlie
Title: Re: Perl Regexp string comparison operators (IF /i modifier) does not work anymore
Post by: Phil Harvey on May 02, 2022, 12:16:37 PM
Hi Charlie,

This still works for me with 12.41 (single quotes because I'm on Mac):

> exiftool a.jpg -filename -if '$filename =~ /A/i'
File Name                       : a.jpg


I also (grudgingly) fired up the Windows VM and tried this (with double quotes) on Windows with 12.41 and it worked fine there too.

Could you give an example of something that doesn't work for you that I can reproduce here?

The only relevant change made in 12.41 was that the -if condition is now evaluated with "use warnings" on Windows as it has always been with the pure Perl version.  This may cause conditions to fail as they should if they generate warnings.

Quote from: Charlie D. on May 02, 2022, 11:47:34 AM
I tried to look the settings up at the old forum, in case I made a mistake. But that site doesn't exist anymore ::)

The thread you were looking for is archived here on this forum (https://exiftool.org/forum/index.php?topic=2129.0).

- Phil
Title: Re: Perl Regexp string comparison operators (IF /i modifier) does not work anymore
Post by: StarGeek on May 02, 2022, 02:23:41 PM
Seems to work here.
C:\>exiftool -ver
12.41

C:\>exiftool -G1 -a -s -if "$CreatorWorkEmail !~ /my\@e-mail.address/i" -CreatorWorkEmail y:\!temp\Test4.jpg
[XMP-iptcCore]  CreatorWorkEmail                : FakeEmail@NoWhere.com

C:\>exiftool -P -overwrite_original -CreatorWorkEmail="My@e-MaIl.AdDrEsS" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -if "$CreatorWorkEmail !~ /my\@e-mail.address/i" -CreatorWorkEmail y:\!temp\Test4.jpg
    1 files failed condition
Title: Re: Perl Regexp string comparison operators (IF /i modifier) does not work anymore
Post by: Charlie D. on May 03, 2022, 12:59:23 AM
Ha thanks!

For example I created two test-images, one with e-mail-address: "My@e-MaIL.adDREss" and one without e-mail-address.
In the screenshot provided I tested the following command lines in which the old ExifTool version was named: "ExifTool_12-40.exe" and the new version: "ExifTool_12-41.exe".

As you can see, the previous version of ExifTool handles the regular expression as it should, 1 file failed the condition. The current version says both files failed the condition, which is wrong.

I hope this explains the bug as I call it, thanks again!
Title: Re: Perl Regexp string comparison operators (IF /i modifier) does not work anymore
Post by: Phil Harvey on May 03, 2022, 12:54:03 PM
You failed to mention that the behaviour is only different for a tag that doesn't exist.

The current behaviour is correct.  A condition should fail if any of the specified tags don't exist.  This is how it has always been for all Perl versions, but previous Windows .exe versions didn't handle this properly.

If you want the previous behaviour, do this:

  -if "not $creatorworkemail or $CreatorWorkEmail !~ /my\@e-mail.address/i"

- Phil
Title: Re: Perl Regexp string comparison operators (IF /i modifier) does not work anymore
Post by: Charlie D. on May 03, 2022, 02:34:19 PM
Yes Phil,

That is exactly the point! Can you explain to me why version 12.41 does not do what the previous versions correctly did?
Version 12.41 does not  recognize the "My@e-MaIL.adDREss" in one of the files using: -if "$CreatorWorkEmail !~ /my\@e-mail.address/i"

So if I run the same command line with different ExifTool versions, they should have a similar output, correct?
Well version 12.40 and older versions do recognize the "My@e-MaIL.adDREss" in one of the example files as you (and I) explained before, where version 12.41 does not!

Please, please look again at the screenshot I provided in my previous message. You have to download it as I don't know how to add it otherwise, I don't have an internet URL for it.
Quote from: Charlie D. on May 03, 2022, 12:59:23 AMIn the screenshot provided I tested the following command lines in which the old ExifTool version was named: "ExifTool_12-40.exe" and the new version: "ExifTool_12-41.exe".

Sorry to be so persistent, but I simply see different output in a command line I'm using for years now...
Where there would not be a difference except for:
Quote from: Phil Harvey on May 02, 2022, 12:16:37 PMthe -if condition is now evaluated with "use warnings" on Windows as it has always been with the pure Perl version.  This may cause conditions to fail as they should if they generate warnings.
An error code or warning is not provided in the output, so to me the -if statement is correct.
The explanation is simple: If CreatorWorkEmail does not contain "My@e-MaIL.adDREss" which is also the case if it is undefined or empty it should do something.

See also the simple Perl if statement at https://www.perltutorial.org/perl-if/ (https://www.perltutorial.org/perl-if/)


I hope this explains the problem, thanks again!
Title: Re: Perl Regexp string comparison operators (IF /i modifier) does not work anymore
Post by: Phil Harvey on May 03, 2022, 02:55:37 PM
Add the -v option to see the warnings generated from -if conditions.

- Phil