develooper Front page | perl.perl6.users | Postings from November 2021

Re: Perl 5 list assignment idiom

From:
rir
Date:
November 13, 2021 16:46
Subject:
Re: Perl 5 list assignment idiom
Message ID:
20211113164549.dbndp6wjmwtaxcgd@localhost

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 does that:

    1 == ( my $script = {1,}() ).elems or die 'Not a 1 element list.';

Rob



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About