in reply to Warning in objImageMagick
Hi Anonymous,
The documentation says:
All PerlMagick methods return an undefined string context upon success. If any problems occur, the error is returned as a string with an embedded numeric status code.
Which means you've got your condition reversed - with or, your warning is displayed when Read returns a false value, but actually, a false value ("an undefined string") means success. There's also this piece of example code:
$x = $image->Read(...); warn "$x" if "$x"; # print the error message $x =~ /(\d+)/; print $1; # print the error number print 0+$x; # print the number of images read
Update: It's been quite a while since I used PerlMagick, but as the documentation and a quick test of the sample code makes clear, the value returned by Read is special and somewhat unusual, so it warrants further explanation: It actually has two different values, one in string context (the error message with an embedded numeric status code, possibly making things even more confusing) and one in numeric context (the number of images read). This means that "$x" and 0+$x, as in the above example, will return two different values. Because it's easy to mix up string and numeric contexts, you should be careful with the return values and follow the code examples from the documentation, i.e. checking "$x" for errors instead of just plain $x.
Hope this helps,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Warning in objImageMagick
by Anonymous Monk on Apr 02, 2016 at 17:24 UTC | |
by haukex (Archbishop) on Apr 02, 2016 at 17:37 UTC | |
by Anonymous Monk on Apr 02, 2016 at 17:45 UTC | |
by haukex (Archbishop) on Apr 02, 2016 at 17:59 UTC | |
by Anonymous Monk on Apr 02, 2016 at 18:23 UTC | |
|