In addition to what davido posted, let me point out that "the space between the curlies" is a magical place, and exploring all its mysteries can lead to countless epiphanies.

For example, there you will find an apparent violation of the Perl dogma that says that "a list can't exist in scalar context." The context between the curlies is a scalar context; this is why, for example, in the following DB interaction, the second line initializes $hash{ 3 }:

DB<1> @subkeys = qw( foo bar baz ) DB<2> $hash{ @subkeys } = 5 DB<3> x \%hash 0 HASH(0x846a000) 3 => 5
Now, in a scalar context, a comma-separated list should evaluate to the last member of the list. Therefore,
$hash{ 'foo', 'bar', 'baz' } = 1;
should amount to initializing $hash{ 'baz' }. Instead, it appears (to those who are not pure of soul) as though the comma-separated list survives long enough in this scalar context for it to be shellacked into a join( $;, LIST ) thingie.

This apparent violation of dogma is resolved by declaring that the commas in $hash{ 'foo', 'bar', 'baz' } are not comma operators; they receive instead special syntactic dispensation from the Holy Interpreter (I'm sure there is a bull or two written on this somewhere).

But the wonders don't end there. It is not just textual commas that receive a special dispensation, but also =>'s, and even the implicit commas in qw() expressions, which leads to great marvels such as

DB<1> $s = qw( eenie meenie minie moe ) DB<2> p $s moe DB<3> $hash{ qw( eenie meenie minie moe ) } = 1234 DB<4> x \%hash 0 HASH(0x846a000) "eenie\c\meenie\c\minie\c\moe" => 1234
I am sure one can derive hours of edifying meditation from variations of these examples.

One last thing: the commas do not get in the way of the auto-quoting that happens inside the curlies. E.g. $hash{ 'foo', 'bar' } and $hash{ foo, bar } refer to the same thing.

the lowliest monk


In reply to Re: $var{'a',1,...} by tlm
in thread $var{'a',1,...} by ady

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.