Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Text::Diff::Table output, but want to show all lines

by Solo (Deacon)
on Dec 12, 2014 at 19:40 UTC ( [id://1110204]=note: print w/replies, xml ) Need Help??


in reply to Re: Text::Diff::Table output, but want to show all lines
in thread Text::Diff::Table output, but want to show all lines

Thanks for the reply, 2teez! Apologies that I wasn't clear enough. Say I have the one-liner, which is not what I'm really trying to do and only to demonstrate the behaviors,
perl -MText::Diff -e '$size = 10; @a = sort map { int rand(100) } 1..$ +size; @b = sort map { int rand(100) } 1..$size; print diff \@a, \@b, +{ STYLE => "Table" };'
I don't quite understand how it's supposed to work without the comma after the 2nd item to compare. If you try that in the one-liner, you'll get the error Not a HASH reference at /usr/local/share/perl/5.18.2/Text/Diff.pm line 46. Pressing on anyway, if I run the one-liner with small size which yields many differences and few matching chunks, I do see all the lines as I want to.
+--+----+--+----+
* 0|12  * 0|0   *
* 1|2   * 1|42  *
* 2|24  * 2|43  *
* 3|26  *  |    |
* 4|29  *  |    |
* 5|3   *  |    |
* 6|4   *  |    |
* 7|48  *  |    |
| 8|49  | 3|49  |
* 9|63  * 4|5   *
|  |    * 5|59  *
|  |    * 6|6   *
|  |    * 7|77  *
|  |    * 8|9   *
|  |    * 9|95  *
+--+----+--+----+
However, when you start running with $size=1000 or $size=10000, you'll see breaks in the output where there are large chunks of identical entries in the lists and only the differences and surrounding context is shown. For example,
...
|     |    * 8127|81  *
|     |    * 8128|81  *
| 8157|82  | 8129|82  |
| 8158|82  | 8130|82  |
| 8159|82  | 8131|82  |
+-----+----+-----+----+  <--- lots of identical entries hidden in that break
| 8255|82  | 8227|82  |
| 8256|82  | 8228|82  |
| 8257|82  | 8229|82  |
* 8258|82  *     |    |
* 8259|82  *     |    |
...
For the normal use of diff, hiding the large identical chunks and showing only the differences with context is desirable (arguably, it's the whole point!) But for what I'm working on now, I want to show all of the roughly 6000 lines even if large chunks are identical. I'm hoping there's a way of forcing that behavior or of controlling whatever the chunk break setting is. :)

Replies are listed 'Best First'.
Re^3: Text::Diff::Table output, but want to show all lines
by Anonymous Monk on Feb 22, 2019 at 14:47 UTC
    I have the same problem. According to some documentation I found,the Context default causes a window of 3 lines around differences to be shown. So need to increase the Window size. Haven't been able to find how to do so. Does anyone out there know?
      #!/usr/bin/perl use strict; use warnings; use Text::Diff; use List::Util qw( max ); my @one = <<END =~ /.*\n/g; one two three four five six seven eight nine ten END my @two = <<END =~ /.*\n/g; one twoplus three four five six seven eight nine tenminus END print "no CONTEXT specified:\n"; print diff \@one, \@two, {STYLE => 'Table' }; print "\nlarge CONTEXT specified:\n"; print diff \@one, \@two, {STYLE => 'Table', CONTEXT => max( $#one, $#t +wo) };

      Outputs:

      no CONTEXT specified: +--+-------+----------+ | 0|one |one | * 1|two |twoplus * | 2|three |three | | 3|four |four | | 4|five |five | +--+-------+----------+ | 6|seven |seven | | 7|eight |eight | | 8|nine |nine | * 9|ten |tenminus * +--+-------+----------+ large CONTEXT specified: +--+-------+----------+ | 0|one |one | * 1|two |twoplus * | 2|three |three | | 3|four |four | | 4|five |five | | 5|six |six | | 6|seven |seven | | 7|eight |eight | | 8|nine |nine | * 9|ten |tenminus * +--+-------+----------+

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-19 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found