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


In reply to Re: Warning in objImageMagick by haukex
in thread Warning in objImageMagick by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.