I assume that by saying "any function, returns 1 upon success", you're referring to functions documented in File::Copy, for they're documented to do just that. In general functions that make system calls return Boolean true upon success, and false upon failure. But check the documentation for specific functions if you want to count on "true" being "1".

Anyway, on to your question. You didn't really explain what it is that you want to do. Your sample code snippet is actually fine, if applied correctly. Here's an example:

if( copy $source, $dest ) { print "Success!"; } else { warn $!; }

The logical short circuit operators, "and", "&&", "or", "||", can be used as a shorthand for more formal or explicit control flow syntax. In the example I provided, I used "if(){}". Here's another:

barf "Green pigs: $!" unless copy $source, $dest;

I'll leave it to you to implement the barf() function. ;)


Dave


In reply to Re: Testing Return Values by davido
in thread Testing Return Values 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.