in reply to Re^16: Why? (each...)
in thread Why? (each...)

I took the context to be like how it was used in the OP -- i.e. something like "When declaring and initializing hashes (%) and arrays (@), do I use {}, [], or () to assign the values?".

Elda Taluta; Sarks Sark; Ark Arks

Replies are listed 'Best First'.
Re^18: Why? (each...)
by ikegami (Patriarch) on May 16, 2011 at 21:40 UTC

    One never uses {} or [] to initialise a hash or array. No need to make stuff up about ().

      The original poster made that exact mistake!!! We're at level 19 and you still haven't figured that out? I guess you just jumped in without reading the entire thread? Impressive trolling!! Well played!! I salute you!! :bow:

      Elda Taluta; Sarks Sark; Ark Arks

        Argel,

        What I think ikegami is trying to point out is this one statement from perldoc:

        List values are denoted by separating individual values by commas (and enclosing the list in parentheses where precedence requires it)

        The only reason the following code doesn't work:

        perl -MData::Dumper -e '%hash = bob => 90, sue => 12; print Dumper(\% +hash);' $VAR1 = { 'bob' => undef };
        ...is because of operator precedence.

        If we look at the operator precedence table we see that assignment "=" comes in at 19 whereas fat comma "=>" and comma "," come in at 20. So in other words, the %hash = bob gets evaluated before the bob => 90, sue => 12 part.

        Up until several minutes ago, when I tried to figure out what ikegami was getting at, I never realized this either. I just blindly memorized and used the (LIST) idiom without understanding why.

        So despite ikegami's seeming inscrutability, I thank him for the new insight.

        The original poster made that exact mistake!!!

        That's my point. That's the answer you should have given if you were answering "When declaring and initializing hashes (%) and arrays (@), do I use {}, [], or () to assign the values?".

        What you actually said is neither a correct answer for that question nor the one that was actually asked, "I still am fuzzy about the difference between “square brackets,” “braces,” and “parentheses.”"

        We're at level 19 and you still haven't figured that out?

        Actually, I realised he made that mistake and addressed it before you even any of these "19 levels" even existed.

        This thread has been about answering your question, "In the context of this discussion, wouldn't it be that parenthesis indicate a list?".

        And the answer is no. Parens don't indicate a list when initialising a hash. The RHS of the assignment will always be a list a value, and a list literal is indicated by commas.