note
robin
This code;
<code>
sub common_path {
my ($p, $q) = ("$_[0]/", "$_[1]/");
(my $pos = ($p ^ $q)) =~ /[^\0]/g;
my $i = 1 + rindex($p, "/", pos($pos) - 2);
return (
substr($p, 0, $i),
substr($p, $i, -1),
substr($q, $i, -1)
);
}
</code>
behaves the same as the last one you posted. It's more efficient as well as simpler (according to my benchmarks).
<p>
I don't think there's any good reason to <tt>use bytes</tt> for this. Were you doing it for efficiency reasons?
508516
508516