[ABE.pm] Re: automating FTP in Perl

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Fri Dec 10 11:56:38 CST 2004


* Faber Fedor <faber at linuxnj.com> [2004-12-10T12:34:43]
>     $ftp->get($ftp_cfg{file}, $datafile)
>         or log_message("tag", "get failed  $ftp->message") && die;
> 
> (where log_message is my function that just calls logger) and the error
> report I get is:
> 
>  Dec 10 12:39:28 myserver tag: get failed Net::FTP=GLOB(0x874b50c)->message
> ...
> I was under the impression that the compiler would interpret everything
> in the double quotes but here it obviously isn't.  Why is that?

You can't interpolate method calls, basically.

> On another note, I'm assuming thatthe reason the "&& die" isn't executed
> is because log_message returns nothing, right?

Presumably, yeah.

Those kinds of long chains are one of the things that people think gets
too confusing in Perl.  I use them now and then, and constantly use
short chains, but it's very common to hear "keep flow control on the
left."  die is flow control, so one would normally write:

	die "error message"
		unless $object->can_do_something_important;

Once you need multiple things to happen, flip it and use a real block.

	unless ($obj->can_do) {
		log_error;
		die "message";
	}

Also, don't use die without an error message.  Even a single word will
make life easier later.

-- 
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/archives/abe-pm/attachments/20041210/7bd2493f/attachment-0001.bin


More information about the ABE-pm mailing list