On Tue, Sep 22, 2009 at 09:40, Bryan R Harris
<bryan_r_har...@raytheon.com> wrote:
>
>
>> On Tue, Sep 22, 2009 at 12:46:59PM +0400, Roman Makurin wrote:
>>> Hi All!
>>>
>>> right now im doing it in following way:
>>>
>>> $size = @{[func_that_return_list_value]};
>>>
>>> is there any best way to do it ?
>>
>> $size =()= func_that_return_list_value;
>
>
> "goatse"?

Don't ask, you really do not want to know.  If you really must, Google
can harm you.

snip
> Can you explain how perl interprets this?  I would've incorrectly thought:
>
> 1)  "() = func_that_return_list_value" tries to assign the list to "()"
> which perl would complain about.
>
> 2)  Then assign the result to $size, which it wouldn't like either.
>
> Just when you think you're starting to understand perl...
snip

The number of "catcher" elements in a list does not need to be equal
to the number of "thrown" items:

my ($x, $y) = (1, 2, 3);

List assignment behaves differently in list and scalar contexts.  In
list context, it returns the list that was successfully assigned to
variables.  In scalar context, it returns the number of items that
tried to be assigned.  So, in

perl -le '$z = ($x, $y) = (qw/a b c/); print "$x, $y, $z"'

$z is 3 (because there were three items in RHS of the assignment), $x
is "a", and $y is "b".  "c" is silently discarded.



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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


Reply via email to