Actually this is a really cool trick

Indeed. I use the return value in list form often (in fact, the code in my original post uses that technique), and it is a useful feature. There are many cases where it is much nicer than the alternatives. That is beside the point, though. The point is, hardburn showed a nifty feature that is somewhat similar, but not quite. I just wanted to explain why it was not quite the same.

hashes (as nice as they are), do not interpolate

Sure, you can't dump the entire hash contents as easily as you can with an array, but individual hash elements interpolate just fine:

my %hash = (one => 1, two => 2); print "$hash{one}\n";

And if you really want the entire hash contents, you can use the array dereference interpolation trick:

print "@{[ %hash ]}\n";

This trick can be used to interpolate arbitrary code, as long as the ultimate return value is an array reference. It is fairly ugly, though, and usually avoided. Here's a simple demonstration:

print "@{ for (1 .. 2) { print qq(Hi!\n); } [ qq(Bye!\n) ]}";

In reply to Re^4: RFC: named pattern match tokens by revdiablo
in thread RFC: named pattern match tokens by revdiablo

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.