Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re^3: Regex - one and only one / at beginning and end of file path

by CombatSquirrel (Hermit)
on Dec 15, 2003 at 18:52 UTC ( [id://314877]=note: print w/replies, xml ) Need Help??


in reply to 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

It concerns checking whether or not a string starts and ends with "/", which was, as far as I can see the OPs question. I do realize that (s)he asked for a RegEx solution, but the "Is the one line solution faster than the two line solution?" part made me think that it was not really relevant in which way checking should occur. I would have assumed that substr was faster than RegExes, because it would just be a simple comparision of an array element (in C -- as I said, I didn't benchmark it, so I am making analogous assumptions) vs. something that hardly could be easier in case of the RegEx. If you say that the RegEx would probably be faster I'll have to believe you, but I don't think that my original reply could really have hurt anyone reading it.
Just my own opinion, though.
CombatSquirrel.
Entropy is the tendency of everything going to hell.
  • Comment on Re: Re^3: Regex - one and only one / at beginning and end of file path
  • Download Code

Replies are listed 'Best First'.
Re^5: Regex - one and only one / at beginning and end of file path
by Aristotle (Chancellor) on Dec 15, 2003 at 20:19 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://314877]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 16:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found