about a statement

about a statement

am 17.04.2008 04:02:04 von Practical Perl

what's this statement?

eval {
require MIME::Base64;
require Authen::SASL;
} or $self->set_status(500, ["Need MIME::Base64 and Authen::SASL
todo auth"]), return 0;

why ', return 0' can be used? I think maybe it should be ';' instead of ',' .
Can I rewrite it as below?

eval {
require MIME::Base64;
require Authen::SASL;
};

if ($@) {
$self->set_status(500, ["Need MIME::Base64 and Authen::SASL todo auth"]);
return 0;
}

Thanks!

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: about a statement

am 17.04.2008 05:19:42 von jialin

------=_Part_36145_28487871.1208402382096
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

comma operator has a higher precedence than 'or' operator,
so when require fails, eval returns undef and perl will
continue to set the status then return 0,

so your rewritten code will work exactly the same as the original code.

On Wed, Apr 16, 2008 at 9:02 PM, Jennifer G.
wrote:

> what's this statement?
>
> eval {
> require MIME::Base64;
> require Authen::SASL;
> } or $self->set_status(500, ["Need MIME::Base64 and Authen::SASL
> todo auth"]), return 0;
>
> why ', return 0' can be used? I think maybe it should be ';' instead of
> ',' .
> Can I rewrite it as below?
>
> eval {
> require MIME::Base64;
> require Authen::SASL;
> };
>
> if ($@) {
> $self->set_status(500, ["Need MIME::Base64 and Authen::SASL todo
> auth"]);
> return 0;
> }
>
> Thanks!
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

------=_Part_36145_28487871.1208402382096--