Re: Counting elements returned from expression

2016-10-05 Thread Chas. Owens
Yep, that is pretty much it. Infix operators can make things like that confusing. For instance, #!/usr/bin/perl use strict; use warnings; my @a = qw/a b c/; my @b = qw/d e f/; my $x = ("a", "b", "c", "d", "e", "f"); my $y = (@a, @b); my $z = (@a[0 .. $#a], @b[0 .. $#b]); print "x $x y $y z $

Re: Counting elements returned from expression

2016-10-05 Thread khalil zakaria Zemmoura
I think I had a problem with my approach. I never thought about assignment operator as returning something at all ! When we include that parameter in the "equation" everything is clear. Since the list assignment is in scalar context, it returns the number of items directly and that number is assig

Re: Counting elements returned from expression

2016-10-04 Thread Chas. Owens
You almost have it. What you are missing is that the list assignment operator is in scalar context and is returning the count, not the list being assigned to. Infix operators obscure things sometimes. It is easier to understand if we rewrite it as if list assignment was a function call instead o

Re: Counting elements returned from expression

2016-10-04 Thread zakaria
To summarize There is a list assignment and the difference between assigning to an empty list and an non empty list is the container(s) inside the liste that capture the different values (scalars or lists or hashes) for example () ans ($a, @b, %c... ) when we assign to an ampty list the values a

Re: Counting elements returned from expression

2016-10-04 Thread Chas. Owens
On Mon, Oct 3, 2016 at 10:45 PM Lawrence Statton wrote: snip > the =()= "operator" just does that without creating a temporary variable snip Almost, but not quite. You can see the difference when =()= is in list context: my @a = (my @temp) = get_clown_hat; my @b = () = get_clown_hat; @a will

Re: Counting elements returned from expression

2016-10-03 Thread Lawrence Statton
On 10/03/2016 06:17 PM, khalil zakaria Zemmoura 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 th

Re: Counting elements returned from expression

2016-10-03 Thread Chas. Owens
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

Counting elements returned from expression

2016-10-03 Thread khalil zakaria Zemmoura
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 th