I don't know how to make that more clearly stated. My code shows a very clear example of not using $1
You mean, this one:
#$string8 = (m/def(\d{8})/)[0]; #alternate way with list slice
How's that different from my:
my $c = ("foo" =~ /($a)*$b/)[0];
which you call an improper use of list slice.. Please spell it out for me, because I don't see the difference.
My code also has the case that $string8 is undefined, which would happen if the match failed.
Given the specific pattern, yes. But it doesn't work in general, as my example shows you can have patterns that match, but leave $1 undefined.

So, let me repeat the question: How do I use list slices in a "proper way" to avoid using $1, while still getting an answer of the question "did the match succeed", and "if it matched, what was captured". In a general way please, not one that works for some patterns, and not for others.

You are saying that if $c is undefined, then the match didn't work.
No, I didn't. I said, if $c is undefined, then you do not know whether the match did, or did not, work.
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.
Bingo! That's what I've been saying.
List slice will not "save the day" in this case. That is why I said it was a misuse.
Oh, now I get it. You say, "In general, I avoid X. Use Y". But when I point out simple patterns where technique Y doesn't work, suddenly technique Y is a misuse of technique Y, even if I use it in exactly the same way as your example. In general, you'd be better of using X, cause that in general just always works. Not technique Y, which would actual inspection of the data before you can determine whether it works or not.

Had you just said "I tend to avoid using $1, if possible I use a list slice", instead of wording it as "In general foo. Use blah.", I wouldn't have replied in the first place.


In reply to Re^6: Question on Regex grouping by JavaFan
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.