note
TomDLux
<p>
Having regexes like <c>s/\/etc\///</c> is referred to as Leaning Toothpick Syndrome, aka LTS.
</p>
<p>You already know you can use your preferred delimiter with <c>qw</c>; same thing with <c>s///</c>. YOu can even use delimiters that come in pairs, to differentiate the search part from the replace part:</p>
<code>
s{/etc/}{}
</code>
I generally like to move the search string and the replace components out of the regex operation, so the operation is just operating on predefined variables.
<code>
my $search_for = qr{/etc/};
my replace_with = qr{};
s{$search_for}{$replace_with}
</code>
<p>
But in this case, you're dropping a single, identical prefix from all the paths. Perhaps that's simply a contrived example for the post. But in such a situation, I would use <c>substr()</c> to discard the prefix, which I already know the length of. While <c>basename()</c> is a more robust, reliable, portable solution, you could also use <c>rindex</c> to locate the rightmost '/' separator, and use substr to extract what comes after that.
</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-144696">
<p>
As Occam said: <em>Entia non sunt multiplicanda praeter necessitatem.</em>
</p>
</div></div>
1078068
1078068