radhika wrote:
Hi,
I have a snippet of code as below.
Even when I return 0 or '', why does @blocks evaluate to true?
If rows returned are 0, then if(@blocks) should evaluate to false, correct?
...
sub do_something
{
        my @row = @_;
        return @row if(@row);
        return '';
}
@blocks = do_something();
if([EMAIL PROTECTED])

When you return '', the @blocks array contains a single element with the value ''. When you test an array with if(), you're evaluating the array in scalar context, which returns the number of elements.

So "if([EMAIL PROTECTED])" is saying "if the @blocks array doesn't contain any elements...". But it *does* contain the single '' element.

Your solution is to use:

   return ();

or just

   return;

This will cause @blocks to receive an empty list and your test will work as you intend.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to