Re: Perl 5 list assignment idiom

2021-11-13 Thread rir
On Mon, Mar 13, 2017 at 11:32:25AM -0700, Sean McAfee wrote: > In Perl 5 ... > 1 == (my ($script) = $page->find('//script')) > or die "Other than exactly one script element found"; > Can a similar expression that avoids an intermediate array variable be > written in Perl 6? This

Re: Perl 5 list assignment idiom

2017-03-13 Thread Brock Wilcox
The == operator coerces to Numeric, so like: > sub one-thing { return ("hi",) } sub one-thing () { #`(Sub|93867233982256) ... } > one-thing.Numeric 1 (mentioned in https://docs.perl6.org/routine/$EQUALS_SIGN$EQUALS_SIGN) I think my does indeed do some fancy precidenting with the assignment.

Re: Perl 5 list assignment idiom

2017-03-13 Thread Sean McAfee
On Mon, Mar 13, 2017 at 12:37 PM, Will Coleda wrote: > Works the same in Perl 6, and you can avoid the parens. Using helper > subs that return one or two item lists, here's some sample code: > > $ perl6 > > sub one-thing { return ("hi",) } > sub one-thing () {

Re: Perl 5 list assignment idiom

2017-03-13 Thread Will Coleda
Works the same in Perl 6, and you can avoid the parens. Using helper subs that return one or two item lists, here's some sample code: $ perl6 > sub one-thing { return ("hi",) } sub one-thing () { #`(Sub|140454852043936) ... } > 1 == my $script = one-thing True > $script (hi) > sub two-things {

Perl 5 list assignment idiom

2017-03-13 Thread Sean McAfee
In Perl 5, list assignment in scalar context evaluates to the number of list elements on the right-hand side. That enables an idiom that I rather like: 1 == (my ($script) = $page->find('//script')) or die "Other than exactly one script element found"; Can a similar expression that