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

I tried to present a simplified answer that I thought would help the OP in the specific situation that came up in the original question.

Perhaps, but the answer you did present was actually harmful.

Perhaps you meant to say that "parens are needed around the list"?

Or to put it differently, how does mentioning using parens to override precedence help the OP?

If you want to open discussions as to how to improve my answer, by all means do so.

But we do that so we can assign a list of key/value pairs to the hash.

Not true at all. Parens are only used in assigning lists of key/value pairs to hashes in a small percentage of situations.

As a side note, in the context being discussed the parens do indicate a list.

Just like my car doesn't indicate a road, those parens don't indicate a list.

Take away the parens, and the list is still there. Replace the list with something else, and you don't have to remove the parens. The parens are in no way related to any list, so they can't possibly indicate a list in «my %hash = ( x=>1, y=>2, z=>3 );».

Replies are listed 'Best First'.
Re^23: Why? (each...)
by jffry (Hermit) on May 18, 2011 at 19:28 UTC

    ikegami,

    Actually, at a certain level of granularity, your car does indicate a road. At least more so than it would indicate a peanut-butter-and-jelly sandwich. And I think that is what Argel is getting at. He is simply suggesting to novice users to memorize the (LIST) idiom when initializing a hash or array and forget about understanding why for now. In his effort to do this, he writes a simplism but that seem not so harmful.

    Argel,

    On the other hand, this is sundialsvc4 asking this, and from what I've seen of his posts, he's more than ready enough to comprehend the full truth: that the parenthesis are just there for operator precedence so the comma expressions get evaluated before the assignment.

    In fact, I also used to trip up now and again while initializing an array or hash and use {} or [] instead of (), but thanks to ikegami's presumably good-intentioned opaqueness, I actually paused and thought about why parentheses, and thus it will never be an issue again for me as I finally understand.

      Actually, at a certain level of granularity, your car does indicate a road.

      Really? Which road does it indicate? I bet you want to answer "the one it's driving on", but it's neither driving nor on a road. So again, which road does it indicate?

      He is simply suggesting to novice users to memorize the (LIST) idiom when initializing a hash or array and forget about understanding why for now.

      As he said, that is what he tried to suggest. "Use (LIST) to initialise a hash or array" is vastly different than "Parens indicate a list."

      The former is explains one method of initialising a hash. The latter is incorrect and doesn't even help in the specific situation it's suppose to help.

        Which road does it indicate?

        No particular road, just the presence of roads in general. My reasoning is sound enough on this point, so I won't engage further. After all, this is Perl Monks, not Phenomenology Monks.

        "Use (LIST) to initialise a hash or array" is vastly different than "Parens indicate a list."

        I'd say "different", but without the adjective "vastly". But again, I won't engage further. I've had my say.

        I see your point. I acknowledge it's correctness. And I am grateful for your effort, and most especially, my new insight.

Re^23: Why? (each...)
by Argel (Prior) on May 19, 2011 at 15:13 UTC
    Interesting how we seem to have never been on the same page on this and probably never will be. As an example:
    But we do that so we can assign a list of key/value pairs to the hash.
    Not true at all. Parens are only used in assigning lists of key/value pairs to hashes in a small percentage of situations.
    Yet that is precisely where the OP made his mistake and thus the actual context I have been discussing this in (and the same situation for arrays)!! Which I have explained before. If we are not on the same page and apparently never will be, then there's no point in continuing.

    Elda Taluta; Sarks Sark; Ark Arks

      You've said two contradictory things repeatedly. That the context is my %hash = ( a => 1, b => 2 );, and that it's about the mistake the OP made. Either one I address, you say the other is the context.

      Both have been addressed.

      It's been shown why parens don't indicate it's a list in my %hash = ( a => 1, b => 2 );.

      It's been shown that saying that parens indicate a list doesn't help initialise a hash correctly.

        How is knowing that parens are used to override precedence helpful to someone that has trouble remembering whether to use %hash=(a=>1,b=>2) vs. %hash={a=>1,b=>2}?!? It's not. And so we are are still not on the same page. And like I said, we probably never will be, especially if you continue to be so hung up on black and white absolutes. I have explained several times now my viewpoint on this and at this point I can only conclude that gray areas like "indicate" are beyond your grasp. If I gave you "%hash=(" and asked you what you would normally expect to follow it what would your answer be? Something like "a=>1,b=>2)"? Edit: And if I gave you %hash=@" what would you expect to follow it? Something like "array"? So given the context, the opening paren does indicate (hint, suggest, pick a synonym) that a list will follow?

        Elda Taluta; Sarks Sark; Ark Arks