 P is for Practical PerlMonks

### Re^4: Not understanding 2 sentences in perldoc

 on Jul 29, 2020 at 20:52 UTC Need Help??

haukex posted "The assignment my (\$x, \$y, \$z) = qw( 1 2 3 ) happens first, i.e. those three variables are assigned the numbers 1 to 3, and this first assignment returns the lvalues, to which the values qw( a b c ) are immediately assigned."

"and this first assignment returns the lvalues" What lvalues does it return? I see (my (\$x, \$y, \$z) = qw( 1 2 3 )) = qw( a b c ); as # 1 = 'a', 2 = 'b', 3 = 'c'.

Replies are listed 'Best First'.
Re^5: Not understanding 2 sentences in perldoc
by LanX (Cardinal) on Jul 29, 2020 at 21:26 UTC
• ( ... ) = is a list assignment with list context inside the parens

we have two nested list assignments here

•  my (\$x, \$y, \$z) = qw( 1 2 3 ) is a list assignment

effect \$x=1, \$y=2, \$z=3

returns lvalues \$x, \$y, \$z in list context

• ( \$x, \$y, \$z ) = qw( a b c ); is a list assignment

effect \$x="a", \$y="b", \$z ="c"

doesn't return because in void context (start statement)

Hints

• If you don't believe it please try it out
• for terminology refer to perlglossary

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Hi, it's me the anonymous monk.

( \$x, \$y, \$z ) = qw( a b c );

Why the above returns void context?

(my (\$x, \$y, \$z) = qw( 1 2 3 )) = qw( a b c );

Does it return void context in this expression too?

Re^5: Not understanding 2 sentences in perldoc
by haukex (Bishop) on Jul 29, 2020 at 20:54 UTC
What lvalues does it return?

Re^2: Not understanding 2 sentences in perldoc
by perlfan (Vicar) on Jul 29, 2020 at 21:02 UTC
This:
``` (my (\$x, \$y, \$z) = qw( 1 2 3 )) = qw( a b c );
Is semantically equivalent to this,
``` my (\$x, \$y, \$z) = qw( 1 2 3 ); # \$x = '1', \$y = '2', \$z = '3'.
(\$x, \$y, \$z)    = qw( a b c ); # \$x = 'a', \$y = 'b', \$z = 'c'.

Create A New User
Node Status?
node history
Node Type: note [id://11120018]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2021-01-20 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
The STEM quote I most wish I'd made is:

Results (220 votes). Check out past polls.

Notices?