in reply to eval failure does not set $@
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.
|
|---|