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 $
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
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
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
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
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
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
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