in reply to Print left-anchored similarities between two strings
String-xor (well, rather ^) to the rescue:
my @strings = qw( /home/usernames/doejohnwilson /home/usernames/doejanemary ); my $common = $strings[0] ^ $strings[1]; # every \x00 means the chars a +re identical my $common_length = 0; if ($common =~ /^(\x00+)/) { $common_length = length $1; }; print substr $strings[0], 0, $common_length;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Print left-anchored similarities between two strings
by Anonymous Monk on Nov 10, 2009 at 17:22 UTC | |
by miketosh (Acolyte) on Nov 11, 2009 at 20:27 UTC | |
|
Re^2: Print left-anchored similarities between two strings
by Anonymous Monk on Nov 11, 2009 at 00:27 UTC | |
by BrowserUk (Patriarch) on Nov 11, 2009 at 00:51 UTC |