in reply to What's happening in this expression?
Can you monks please explain step-by-step what computations will happen here?
Under strict, none, because it will not compile unless $x, $y, and $z have been previously declared. Otherwise, B::Deparse helps:
$ perl -MO=Deparse,-p -e 'my $a, $x, $y, $z = foo()' (my($a), $x, $y, ($z = foo()));
In other words, it's declaring a lexical $a, then $x and $y are simply sitting there, and then $z is assigned the return value of the function call foo() - although if that's not defined, that call will fail. See also Comma Operator. Turning on warnings gives some relatively helpful hints:
$ perl -w -e 'my $a, $x, $y, $z = foo()' Parentheses missing around "my" list at -e line 1. Useless use of a variable in void context at -e line 1. Useless use of a variable in void context at -e line 1. Name "main::x" used only once: possible typo at -e line 1. Name "main::z" used only once: possible typo at -e line 1. Name "main::y" used only once: possible typo at -e line 1. Undefined subroutine &main::foo called at -e line 1.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: What's happening in this expression?
by zapdos (Sexton) on Oct 11, 2020 at 09:58 UTC | |
by haukex (Archbishop) on Oct 11, 2020 at 10:08 UTC | |
by zapdos (Sexton) on Oct 11, 2020 at 14:02 UTC | |
by haukex (Archbishop) on Oct 11, 2020 at 14:26 UTC | |
by perlfan (Vicar) on Oct 11, 2020 at 10:09 UTC |
In Section
Seekers of Perl Wisdom