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 { return <hi there> }
sub two-things () { #`(Sub|140454852044088) ... }
> 1 == my $bar = two-things
False
> $bar
(hi there)



On Mon, Mar 13, 2017 at 2:32 PM, Sean McAfee <eef...@gmail.com> wrote:
> 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 avoids an intermediate array variable be
> written in Perl 6?
>



-- 
Will "Coke" Coleda

Reply via email to