in reply to RFC: Destructuring Assignment (aka Unpacking aka Type Patterns) in pure Perl

[ Ignore ]

Perl doesn't have a destructuring assignment because it's a workaround for the inability to return multiple values that Perl has naturally.

[ a, b, ...rest ] // ES6 { a:4, b:5, ...rest } // ES6

is the same as

[ $a, $b, @rest ] # Perl { a=>4, b=>5, %rest } # Perl

Alternatively, you could argue that ... is known as ->@* and ->%* in Perl.

[ a, b, ...[ c, d ] ] // ES6 { a:4, b:5, ...{ c:6, d:7 } } // ES6

is the same as

[ $a, $b, [ $c, $d ]->@* ] # Perl { a=>4, b=>5, { c=>6, d=>7 }->%* } # Perl

Update: Changed the layout of the answer.

Replies are listed 'Best First'.
Re^2: RFC: Destructuring Assignment (aka Unpacking aka Type Patterns) in pure Perl
by LanX (Saint) on Jul 03, 2020 at 20:13 UTC
    > because it's a workaround for the inability to return multiple value that Perl has naturally.

    O rly? ;)

    const metadata = { title: 'Scratchpad', translations: [ { locale: 'de', localization_tags: [], last_edit: '2014-04-14T08:43:37', url: '/de/docs/Tools/Scratchpad', title: 'JavaScript-Umgebung' } ], url: '/en-US/docs/Tools/Scratchpad' }; let { title: englishTitle, // rename translations: [ { title: localeTitle, // rename }, ], } = metadata; console.log(englishTitle); // "Scratchpad" console.log(localeTitle); // "JavaScript-Umgebung"

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

        You do realize that Perl can't do this naturally, right?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Re^2: RFC: Destructuring Assignment (aka Unpacking aka Type Patterns) in pure Perl
by ikegami (Patriarch) on Jul 03, 2020 at 20:15 UTC