In general, I avoid using $1, $5 etc. Use Perl list slice instead.

I don't know how to make that more clearly stated. My code shows a very clear example of not using $1. My code also has the case that $string8 is undefined, which would happen if the match failed. Often in parsing, it is desired to keep going, not in this case perhaps but that does happen. I showed the place to do that if this is necessary - there is a comment block about that.

In Perl 5.10, $string8 //= ''; Sets $string8 to null string if $string8 is undefined. In older Perl, we only had $string |= ''; which is not quite the same thing. The new Perl operator tests for "definedness" instead of "truthfulness". But anyway there is a place in the code to use that info.

In your code: "Did it match, or didn't it? If $c is defined, it matched. But what if $c isn't? If $a eq "g", and $b eq "o", there is a match, but $c is undefined."

You are saying that if $c is undefined, then the match didn't work. Ok. True. What else is there to say about this? I said that this was a misuse of list slice, because you were presenting this as case where list slice didn't work. Perhaps my English prose wasn't as quite as well written as it could have been. Ok, if $c is undefined, then there is no information other than "it didn't work". List slice will not "save the day" in this case. That is why I said it was a misuse.

Javafan is a very, very high level Monk and you know perhaps even more than I do, that often what is asked in a post is not what is really needed. I offered a credible solution to what I thought the OP needed and in addition showed ways to extend that solution. The OP thanked me. So, what problems remain? I think none.

You think that list slice is "ugly". Ok. It might very well be! I would suggest that we leave this thread and that you start a new thread: re: "what are proper uses of list slice?". And I am sure that this will be one of the most talked about threads in recent history.


In reply to Re^5: Question on Regex grouping by Marshall
in thread Question on Regex grouping by ajguitarmaniac

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.