Logical Expressions with emply tag

Started by lei, March 18, 2024, 01:17:49 PM

Previous topic - Next topic

lei

Dear Forum Experts,

While working with logical expressions to search files, I encountered an intriguing issue.

Here's the expression I employed:

-if ($IFD0:XPAuthor=~/catherine/i) or ($IFD0:Model=~/eva/i)

The problem arises when XPAuthor is not initialized; the entire expression fails regardless of whether the second condition is true or false. I had expected the "or" operator to allow evaluation of the second expression if the first one is false (either due to the tag not being initialized or not equal to "catherine"). However, this was not the case.

To ensure the condition functions correctly, I had to check if the tag exists before assessing its value, resulting in the following adjustment:

-if ($IFD0:XPAuthor and $IFD0:XPAuthor=~/catherine/i) or ($IFD0:Model=~/eva/i)

This workaround feels cumbersome. Is there a more efficient way to achieve the desired outcome without the need for preliminary testing?

Thank you in advance for your assistance!

Phil Harvey

You can either use the -f option to set undefined tags to "-", or the -m option to set undefined tags to "".  Both of these options have other side effects, so you should read up on them to see which is best for you.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

lei

Quote from: Phil Harvey on March 19, 2024, 08:07:27 AMYou can either use the -f option to set undefined tags to "-", or the -m option to set undefined tags to "".  Both of these options have other side effects, so you should read up on them to see which is best for you.

- Phil

Great! That's much easier. Thanks!