Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

stvn_skuo (5628)

Journal of stvn_skuo (5628)

Friday August 05, 2005
01:13 AM

Just in time

[ #26114 ]
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($_)     =>
    <DATA>;

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;
        }

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.