Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by Solo (Deacon)
on Dec 11, 2014 at 21:28 UTC ( #1110106=perlquestion: print w/replies, xml ) Need Help??

Solo has asked for the wisdom of the Perl Monks concerning the following question:

I really like the output of Text::Diff::Table. But sometimes I want to show all the lines, not only the differences with surrounding context. Is there an option to do this in Text::Diff::Table? (I peeked at the code, but didn't see anything obvious.) Or is there another module that might do the trick?
  • Comment on Text::Diff::Table output, but want to show all lines

Replies are listed 'Best First'.
Re: Text::Diff::Table output, but want to show all lines
by 2teez (Vicar) on Dec 12, 2014 at 01:36 UTC

    Hi Solo,
    ..But sometimes I want to show all the lines, not only the differences with surrounding context..

    I don't know how you are using Text::Diff::Table and what you mean to show all the lines.
    For in my experience, I have a table of all the lines. And the lines with difference are indicated by * at both side of the table, showing both files.
    More like what diff command in Linux will give you when used with the option y like so: diff -y file1 file2

    Update:

    If you do this, in your script
    my $diff = diff $file1, $file2, { STYLE => "Table" }; print $diff;
    You will have a table, comparing the two files, and showing differences. Just like I mentioned previously.

    But without the { STYLE => "Table" } in that script, you will only have want I suppose you have now.
    And like I said, you weren't telling how you are using the module. But, I think this is what you want.

    Please Note:
    That if you use diff $file1, $file2 { STYLE => "Table" }; as given from the documentation of Text::Diff::Table, which is a bit different from that of Text::Diff. Note there is no , after $file2, before {. And that without the use strict; pragama, you have just the difference between the files listed and no error BUT with the use strict;, you will end up with compilation errors.

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
      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. :)
        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?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2021-08-05 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?