Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Poor man's diff

by kaif (Friar)
on Jun 03, 2005 at 20:28 UTC ( #463400=note: print w/ replies, xml ) Need Help??


in reply to Poor man's diff

Good code.

However, you said that you knew no way to "tell Text::Diff to ignore trailing blanks as being insignificant." I decided to explore this and found that the following code works:

#!/usr/bin/env perl die "Usage: $0 from-file to-file\n" unless @ARGV == 2; use Text::Diff; diff shift, shift, { OUTPUT => \*STDOUT, STYLE => "OldStyle", # or whatever pleases you KEYGEN => sub{ (my $line = shift) =~ s/\s*$//; return $line; }, };
In general, to compare something other than the lines themselves, just return that from the KEYGEN argument. For example, inserting sub{return substr shift, 0, 1} compares only the first characters. Unfortunately, the documentation for this is hidden in Algorithm::Diff.


Comment on Re: Poor man's diff
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://463400]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2015-07-02 01:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls