So, list assignment is

my ($foo, $bar, $baz) = ("a", "b", "c");

$foo will be "a", $bar will be "b", etc. There can be more items on the
right hand side and they won't be copied. This operation has a return
value. In list context it is the list of values that got assigned. In
scalar context it is the number of items on the right hand side of the list
assignment.

So, $count will be 3 in

my $count = my ($foo, $bar, $baz) = ("a", "b", "c");

Since it is the number of items on the right hand side of the list
assignment and the number of items on the left hand side doesn't have to
match the right hand side, you can say

my $count = () = ("a", "b", "c");

And $count will be 3.

Hope that helps.

On Mon, Oct 3, 2016, 19:19 khalil zakaria Zemmoura <
zemmoura.kha...@gmail.com> wrote:

> Hi,
> I am reading modern Perl and despite the explanation of the author I
> couldn't understand:
>
> my $count = () = get_clown_hats()
>
> It's obvious to me that the function get_clown_hat() is evaluated in list
> context but what the author said is that
> the assignment to the empty list throws away all of the values of the
> list, but the assignment takes place in scalar context, which evaluates to
> the number of items on the right!
>
> If someone could explain that, it would be great.
>
> Thanks
> Regards
>

Reply via email to