in reply to Re^2: Question on Regex grouping
in thread Question on Regex grouping
"Additional parens don't contribute that much".
Fair enough, there is overhead in doing it at all. I am saying "don't over do it".
list slice, hash slice, etc are some of the most cool features in Perl! You are completely correct in that list slice does not "play well with match global" because the number of things that can be returned is variable and therefore there is no way to specifiy a subset of range indicies that are of interest.
The classic example of list slice is used when spliting a line and you want 127,[3..5],93,8 things on that line. And I do work with DB lines like that - it is actually common for such a thing. List slice allows me to assign those 6 things directly into variables that mean something within the program. I usually assign vars on the left ($x,$y,$z..) in the order that the following code will use them. And adjust the slice accordingly.
If you are saying that "do not use list slice when doing a match global", I would absolutely agree with that. And I do not think that I have recommended that.
In your code, my $c = ("foo" =~ /($a)*$b/)[0]; is an improper use of list slice.
Properly used, list slice is beautiful.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Question on Regex grouping
by JavaFan (Canon) on Dec 21, 2010 at 13:57 UTC | |
by Marshall (Canon) on Dec 21, 2010 at 15:10 UTC | |
by JavaFan (Canon) on Dec 21, 2010 at 16:31 UTC |