Following the eval we are check $@ to verify the eval was successful.

There was/is a bug in eval that means the eval { ... }; if ($@) { ... } pattern is not reliable (even though it still appears in examples all over the web). It's much better to do eval { ...; 1 } or do { ... };, or use a module like Try::Tiny.

We are building the put command on the fly and then executing 'eval $PutCMD'.

I don't quite understand why you're doing it this way - you might get bitten by quoting/escaping issues. Note that you can always just pass an array of arguments to a method, and build that array dynamically. This example should do the same as the command you showed:

my @args = ("$opt_local_dir/$do_file"); push @args, $remote_file, copy_perms => 0; push @args, copy_time => 0; eval { $ftp->put(@args); 1 } or warn "put failed: ".($@//"unknown error");

Note that's eval BLOCK, not eval STRING, which means the code contained in the BLOCK is compiled and checked for syntax errors along with the surrounding code, and at runtime just functions as an error catching mechanism.


In reply to Re: eval failure does not set $@ by haukex
in thread eval failure does not set $@ by wanderedinn

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.