in reply to Remove a common prefix from two strings

Acknowledgement: this comment is here thanks to this post and the resulting thread :)

No need to disable warnings, you don't need chr at all:

#!/usr/bin/perl use warnings; use strict; my $str0 = "C:/Build~~/Win/App/Experiments/1_0/"; my $str1 = "${str0}Experiments/Blood Pressure/_pieces"; my $str2 = "${str0}temp/Blood Pressure/_pieces"; my $commonLen = 0; ($str0 ^ $str1) =~ /^(\0*)/; $commonLen = $+[0]; my $commonStr = substr $str1, 0, $commonLen, ""; substr $str2, 0, $commonLen, ""; print "Common: $commonStr\n"; print "Tail 1: $str1\n"; print "Tail 2: $str2\n";

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

Replies are listed 'Best First'.
Re^2: Remove a common prefix from two strings
by GrandFather (Saint) on Aug 05, 2005 at 02:26 UTC

    Thanks frodo72. I knew there was a way of quoting a char in that fashion (but couldn't find it quickly) and I just didn't try the obvious way :(


    Perl is Huffman encoded by design.