A rule of thumb would not be in the official documentation. Yes, character classes are better than wildcards.
The regex you have start with .*, which will match the entire string. It will then look for the next pattern, a minus sign. Since it's at the end of the string, it will fail. It will back up on character and look for the minus sign there. Not finding it, it will back up one more, Etc. Not very efficient.
The backslash before the minus is not needed but I tend to program defensively. A backslash before any ASCII non-letter will escape it. This is in case a new meta-character is added in the future.
You may be correct in that the regex I gave may not be more efficient in that it too has backtracking. A more efficient way would be:
$module =~ s/\-[^-]*+$//;The extra plus sign stops backtracking. This regex would scan until a minus sign, scan non-minus-signs, and look for the end of the string. If it's not at the end, the entire pattern will fail and it will have to start over. That is, it will start the pattern from the beginning but from where it currently is in the string. It will scan the string in one pass without any backtracking.
In reply to Re^3: find module name from the module archive
by shawnhcorey
in thread find module name from the module archive
by Lotus1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |