in reply to Re: Re^3: Regex - one and only one / at beginning and end of file path
in thread Regex - one and only one / at beginning and end of file path
But the OP was trying to make sure that the string has exactly one slash at both ends. Your snippet does not check for multiple slashes nor does it do anything about missing ones. The "blanks" that have to be filled in your approach basically consistute the entire solution.
As for the performance, this is Perl, not C; a string is not just a pointer to a chunk of bytes in memory, but wrapped in a complex data structure, and so is substr's return value. Then there's the need to have a lot of explicit ops in the optree, and on the other hand, there's the many (though specific) optimizations the regex engine has enjoyed. Optimizing a highlevel language like Perl, if you even want to, is a very different science from optimizing a lowlevel language like C.
Makeshifts last the longest.
|
|---|