note
ikegami
<p>Since you're searching for a constant string, <code>index</code> is faster than a regexp:</p>
<code>
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");
}
</code>
<p>Or since you probably meant to search for <code>/^\Q$svnroot\E/</code> (i.e. search for $svnroot at the beginning of the string), this is more precise and even faster:</p>
<code>
foreach my $elem (@repos) {
if (lc($svnroot) eq substr(lc($elem), 0, length($svnroot))) {
print(substr($elem, length($svnroot)), "\n");
} else {
print("$elem\n");
}
}
</code>
463914
463914