in reply to Re^5: Question on Regex grouping
in thread Question on Regex grouping
I don't know how to make that more clearly stated. My code shows a very clear example of not using $1You mean, this one:
How's that different from my:#$string8 = (m/def(\d{8})/)[0]; #alternate way with list slice
which you call an improper use of list slice.. Please spell it out for me, because I don't see the difference.my $c = ("foo" =~ /($a)*$b/)[0];
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.
|
|---|