[Israel.pm] boolean statment as sub parameter
Avishalom Shalit
avishalom at gmail.com
Sun Feb 22 23:15:04 PST 2009
well an example for "and" is like a conditional (upon success)
so
do_this() and do_that() and do_the_other_thing()
will only do_the_other_thing if the first two were successful
2009/2/22 Yitzchak Scott-Thoennes <sthoenna at efn.org>:
> On Sun, February 22, 2009 10:36 am, ik wrote:
>> demo($var1, ($id >= 1) and data_exists(...), "18");
>
> To add a little to what Gabor said:
>
> "and" and "&&" differ in precedence. "and" is designed to be used in flow
> control, "&&" to be used in shorter expressions.
>
> So, you might say something like:
>
> supply_default_values() and $x = 123;
>
> which, using &&, would need to be explicitly parenthesized:
>
> supply_default_values() && ( $x = 123 );
>
> (It's actually kind of hard to come up with good "and" examples; "or"
> is a lot more useful.)
>
> But even with &&, you have a potential problem:
> Subroutine parameters are in list context. && will force it's
> left operand into scalar context, but propagates the context of
> the &&-expression onto the right operand, so data_exists() is
> in list context. If $id is in fact >= 1 and data_exists returns
> 0 elements, or 2 or more, you aren't going to have the parameters
> you expect. People often get into this trouble using CGI::param in
> subroutine parameters or array or hash initializers.
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>
--
-- vish
More information about the Perl
mailing list