Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^5: Not understanding 2 sentences in perldoc

by LanX (Cardinal)
on Jul 29, 2020 at 21:26 UTC ( #11120027=note: print w/replies, xml ) Need Help??


in reply to Re^4: Not understanding 2 sentences in perldoc
in thread Not understanding 2 sentences in perldoc

  • ( ... ) = 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

Replies are listed 'Best First'.
Re^6: Not understanding 2 sentences in perldoc
by zapdos (Sexton) on Jul 29, 2020 at 22:01 UTC
    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?

        I see. But I want to know why in my ($x, $y, $z) = qw( 1 2 3 ); it's returning the lvalues in list context and why in ( $x, $y, $z ) = qw( a b c ); it's returning nothing?

        And in the expression (my ($x, $y, $z) = qw( 1 2 3 )) = qw( a b c ); it's returning nothing as well?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11120027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2021-01-20 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?