Esteemed monks,

In my laziness, impatience, and hubris I have reached the conclusion that this question is worthy of your attention. If I am mistaken, please put the blame on one of the aforementioned personality traits.

I'd like to access the result of a pattern match as an array without assigning it to a variable first. Doing this the non-lazy way goes like this:

@matches = "hello awesome" =~ /(el).*(om)/; print pop @awesome;

but this is clearly unacceptable.

I've tried a couple of different approaches, which give different errors:

The Book $(man perldata) mentions that the Great Creator of perl has given it 'three built-in data types: scalars, arrays of scalars, and associative arrays of scalars, known as "hashes"'. However I see now that there are some quantum particles whose existence proves such dogma to be somewhat oversimplified. The psalm $(perldoc -f scalar) does provide a solution to my practical concerns:

$ perl -we 'print ${["hello awesome" =~ /(el).*(om)/]}[1];' om
but also mentions that "There is no equivalent operator to force an expression to be interpolated in list context because in practice, this is never needed."

This revelation suggests that there may be a better way to do this, and also increases my hunger for understanding of the Great Mysteries of perl.

And so it is with humilityhubris that I submit my request for knowledgeassume that my lack of understanding of this aspect of perl is due to a flaw in the documentation, not in my (lack of)? reading of it. Or rather ask for clarification of this aspect of the voluminous and esoteric Literature from those appointed as its interpreters.

Thank you, o great esteemed Monks.


In reply to accessing the result of a match as an array by intuited

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.