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"); } }
|
---|
In Section
Seekers of Perl Wisdom