Just in time

stvn_skuo on 2005-08-05T06:13:54

Thanks rafael.   I was just looking for a way to compare files as strings and found File::Compare a bit lacking.



Looks like someone else besides me would like an option to ignore differences in number of whitespaces.   Other options I often use with the Unix diff utility include those to

  • ignore differences between lower- and upper-case letters, and


  • expand tabs to whitespace.



I suppose I could preprocess the strings before handing them off to is_string():


use Text::Tabs;
use Test::More tests => 1;
use Test::LongString;

# Apply one or more filters. # N.B. The order in which the filters are applied matters:

my @strings = map {tr/\n\r\f / /s; $_} map expand($_) => map lc($_) => ;

is_string( $strings[0], $strings[1], 'Actually differs by one char' );

__DATA__ This is a test of Test::LongStrings this is a test of Test::longstring







As far as the _common_prefix_length function is concerned, perhaps using substr would be a bit faster?



     while (length($x) && length($y)) {
-       my ($x1,$x2) = $x =~ /(.)(.*)/s;
-       my ($y1,$y2) = $y =~ /(.)(.*)/s;
+        my $x1 = substr($x, 0, 1, '');
+        my $y1 = substr($y, 0, 1, '');
        if ($x1 eq $y1) {
-           $x = $x2;
-           $y = $y2;
            ++$r;
        }