Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

This post http://www.daemon.de/blog/2014/12/30/383/re-perl-jam-exploiting-20-year-old-vulnerability-31c3/ details a claim that perl has a security flaw, and rejects that claim.

Apparently this:

my @a = qw(8 foo 666); my %h = (foo => 100, bar => 333, san => @a); print Dumper(\%h); $VAR1 = { 'san' => 8, 'bar' => 333, 'foo' => 666 };

Is expected behaviour and not a problem. Happy to accept that, but can someone talk me through it? I've been working with perl for many years and never heard the word "dissolve" used before.

Replies are listed 'Best First'.
Re: Why does an array "dissolve" into a hash?
by Athanasius (Archbishop) on Aug 20, 2015 at 01:20 UTC

      Ah, that makes sense. Thank you. Is the use of the word "dissolve" normal here?

        "Flattened into a list" is the commonly used, though it's a bit of a misnomer. The array doesn't get flattened into another data structure; an array simply returns its elements in list context.
        Never heard it used that way before.
Re: Why does an array "dissolve" into a hash?
by LanX (Saint) on Aug 20, 2015 at 01:10 UTC
    >     my %h = (foo => 100, bar => 333, san => @a);

    It's only a list assignment.

    The right hand side is just a list, and arrays are flattened to lists.

    And the => is not a key-value separator, but just a "fat comma" which auto quotes the LHS.

    That's why stuff like

    %h = ( %a , %b )

    or

    %h = ( "foo", 100 , "bar" , 333)

    (or both)

    work.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

    update

    ²) added example with comma instead of =>

Re: Why does an array "dissolve" into a hash? (unlocked doors parody spam)
by Anonymous Monk on Aug 20, 2015 at 03:30 UTC

    See Stop Using Perl

    Its like having a fancy lock but always leaving it open/unloacked ... then blame lock manufacturer ... as a form of self-promotion ie spam