ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Birdman on March 09, 2023, 08:50:37 AM

Title: Brackets for multiple IFs
Post by: Birdman on March 09, 2023, 08:50:37 AM
Hello,

is there a way to use something like brackets for more complex IF commands? I know of "and", "or", but how can those be combined for complex commands? For example:
-if "$var1 eq '1' and $var2 eq '2' or $var3 eq '3'"
With brackets this could be meant as
-if "$var1 eq '1' and ($var2 eq '2' or $var3 eq '3')"or
-if "($var1 eq '1' and $var2 eq '2') or $var3 eq '3'"
Title: Re: Brackets for multiple IFs
Post by: StarGeek on March 09, 2023, 10:33:30 AM
Your examples show the correct way to set precedence.  Exiftool is written in Perl, so you can look at any Perl tutorial on its operators.
Title: Re: Brackets for multiple IFs
Post by: Phil Harvey on March 10, 2023, 07:24:06 AM
From the perlop man page:

       Perl operators have the following associativity and precedence, listed
       from highest precedence to lowest.  Operators borrowed from C keep the
       same precedence relationship with each other, even where C's precedence
       is slightly screwy.  (This makes learning Perl easier for C folks.)
       With very few exceptions, these all operate on scalar values only, not
       array values.

           left        terms and list operators (leftward)
           left        ->
           nonassoc    ++ --
           right       **
           right       ! ~ \ and unary + and -
           left        =~ !~
           left        * / % x
           left        + - .
           left        << >>
           nonassoc    named unary operators
           nonassoc    < > <= >= lt gt le ge
           nonassoc    == != <=> eq ne cmp ~~
           left        &
           left        | ^
           left        &&
           left        || //
           nonassoc    ..  ...
           right       ?:
           right       = += -= *= etc. goto last next redo dump
           left        , =>
           nonassoc    list operators (rightward)
           right       not
           left        and
           left        or xor

- Phil