Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: search and replace frustration

by ikegami (Patriarch)
on Jun 06, 2005 at 14:51 UTC ( [id://463929]=note: print w/replies, xml ) Need Help??


in reply to search and replace frustration

Since you're searching for a constant string, index is faster than a regexp:

foreach my $elem (@repos) { my $repo_name = $elem; my $pos = index(lc($repo_name), lc($svnroot)); if ($pos >= 0) { substr($repo_name, $pos, length($svnroot), ''); } print("$repo_name\n"); }

Or since you probably meant to search for /^\Q$svnroot\E/ (i.e. search for $svnroot at the beginning of the string), this is more precise and even faster:

foreach my $elem (@repos) { if (lc($svnroot) eq substr(lc($elem), 0, length($svnroot))) { print(substr($elem, length($svnroot)), "\n"); } else { print("$elem\n"); } }

Log In?
Username:
Password:

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

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

    No recent polls found