Roman Makurin wrote:
> On Wed, Jun 24, 2009 at 03:25:57PM +0200, Jenda Krynicky wrote:
>> From: Roman Makurin <dro...@gmail.com>
>>> here is complite perl script which produces such results without
>>> any warning:
>>>
>>> #!/usr/bin/perl
>>>
>>> use strict;
>>> use warnings;
>>>
>>> use constant {
>>>     A => 0,
>>>     B => 1,
>>>     C => 2 };
>>>
>>> my @a = (A, B, C);
>>> my @b = (1, 2, 3);
>>>
>>> while(my $i = shift @a) {
>>>     print $i, $/
>>> }
>> But of course this does not print anything. The shift(@a) returns the 
>> first element of @a which is zero, assigns that to $i and then checks 
>> whether it's true. And of course it's not. So it skips the body and 
>> leaves the loop. Keep in mind that the value of
>>
>>    my $i = shift @a
>>
>> is NOT a true/false whether there was something shifted from the 
>> array. It's the value that was removed from the array and assigned to 
>> the $i. And if that value it false (undef, 0, 0.0, "0", "0.0", "" - 
>> if I remember rigth) then the whole expression evaluates to false in 
>> boolean context.

If I understand correctly, what you are saying is that while() is
evaluating the left side of the '=' as it's condition, culminating into:

while($i)

Which eventually equates into:

while(0)

...on the very first pass.

>> Whether you use constants or not is irrelevant. You'd see the same 
>> behaviour with
>>
>> my @a = (0, 1, 2);
> 
> big thanks for explanation :)

+1.

Steve

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to