Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 524 forks source link

[doc] perlref postfix dereference can be used on LHS #22130

Open epa opened 3 weeks ago

epa commented 3 weeks ago

Where perlref section Postfix Dereference Syntax

Description The documentation is accurate to say that postfix deref works in all cases where block deref does. But it doesn't specially mention that this includes on the LHS of an assignment. It could do with a mention of $aref->@* = (1, 2, 3); # same as @{ $aref } = (1, 2, 3) just to reassure the reader.

(what follows is more of an opinion and might or might not be suitable for incusion in perlref) Perhaps a common usage of postfix on the LHS would be for $aref->@* = foo(); This is, of course, not equivalent to $aref = [ foo() ]; but it can be a good enough replacement in many cases, when you know $aref was undefined before, and is visually easier to read.