in reply to Re^3: Warning in objImageMagick
in thread Warning in objImageMagick

Did this way and it oppressed the warnings:
my $obj_temp = ""; $obj_temp = $objImageMagick->Read("dir/$filename"); warn "$obj_temp" if $obj_temp =~ /(\d+)/; # print the error message warn "Error Number: ".$1." Number of images read: ".0+$obj_temp if +$obj_temp =~ /(\d+)/;

Replies are listed 'Best First'.
Re^5: Warning in objImageMagick
by haukex (Archbishop) on Apr 02, 2016 at 17:59 UTC

    Hi Anonymous,

    Actually there's still a bug in there, you'll still get the same "Argument ... isn't numeric in addition" warning when Read fails. warn "message... ".0+$obj_temp is interpreted by Perl as warn "message... 0" + $obj_temp; (i.e. the concatenation happens first) instead of what you want, warn "message... ".(0+$obj_temp). Try it yourself: perl -MO=Deparse,-p -e 'warn "message... ".0+$obj_temp'

    The reason is the operators + and . have the same precedence but are left associative (compare the output of the aforementioned Deparse with this: perl -MO=Deparse,-p -e 'warn 0+$obj_temp."message... "'). You should use parentheses to set the precedence and for clarity.

    Regards,
    -- Hauke D

      So this line should be like this:
      warn "Error Number: ".$1." Number of images read: ".(0+$obj_temp) if $ +obj_temp =~ /(\d+)/;

        Hi Anonymous,

        Yes, that's correct. Personally I'd write it with an if (...) {...} as I showed in Re^3: Warning in objImageMagick, but since either works, it's up to you.

        Regards,
        -- Hauke D