I cannot exactly understand how the following snippet works:
my $str = 'abc def ghi';
my $num = () = $str =~ /\w+/g;
say $num; # prints the word count, 3
I know that $str =~ /\w+/g
returns a list of the words which, apparently, is conveyed to the leftmost assignment. Then $num
imposes a scalar context on that list and becomes 3.
But what does () = ('abc', 'def', 'ghi')
mean? Is it something like my $a = my @b = (3, 5, 8)
? If so, how is the list at the rightmost side transferred to $num
at the leftmost side?