Tux / Text-CSV_XS

perl5 module for composition and decomposition of comma-separated values
17 stars 20 forks source link

csvdiff #47

Closed x12340 closed 1 year ago

x12340 commented 1 year ago

Hello!

I am using: -> Text-CSV_XS-1.50 -> Strawberry perl, Perl version: 5.36.0 / MSWin32-x64-multi-thread

I try to compare two CSV files "file1.csv" and "file2.csv" with the script "csvdiff". I do not apply any changes inside this script. My goal is to use this approach for bigger csv data files. In all the cases I use the command: perl csvdiff file1.csv file2.csv

file1.csv a,b,c,d 1,2,3,4 5,6,7,8

file2.csv (here the change is the "X" in the last row) a,b,c,d 1,2,3,4 5,6,X,8

Here as expected is presented that 7 is replaced by X: "# csvdiff < file1.csv > file2.csv" "< 5,6,"[31m7[0m",8[0m" "> 5,6,"[32mX[0m",8[0m"

But when compare these files with the same content: file1.csv a,b,c,d 1,2,3,4 5,6,7,8 9,10,11,12 13,14,15,16 17,18,19,20

file2.csv a,b,c,d 1,2,3,4 5,6,7,8 9,10,11,12 13,14,15,16 17,18,19,20

Why the result is: "# csvdiff < file1.csv > file2.csv" "< 9,10,11,12[0m" "> 9,10,11,12[0m" "< 17,18,19,20[0m" "> 17,18,19,20[0m"

By the way in all these cases when I use the option "-h", with the command:

perl csvdiff -h file1.csv file2.csv

the result is: The getpwuid function is unimplemented at csvdiff line 61.

How to apply a html support?

Thanks!

Tux commented 1 year ago

HTML on Windows:

diff --git a/examples/csvdiff b/examples/csvdiff
index 804e248..131704a 100755
--- a/examples/csvdiff
+++ b/examples/csvdiff
@@ -1,12 +1,12 @@
 #!/pro/bin/perl

-use strict;
+use 5.012000;
 use warnings;

 # csvdiff: Show differences between CSV files
-#         (m)'19 [05 Mar 2019] Copyright H.M.Brand 2009-2023
+#         (m)'23 [05 Aug 2023] Copyright H.M.Brand 2009-2023

-our $VERSION = "1.02 - 20190305";
+our $VERSION = "1.03 - 20230805";

 sub usage {
     my $err = shift and select STDERR;
@@ -51,14 +51,15 @@ my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 0 });

 if ($opt_h) {
     binmode STDOUT, ":encoding(utf-8)";
-    print <<EOH;
+    my $name = $^O eq "MSWin32" ? Win32::LoginName () : scalar getpwuid $<;
+    print <<"EOH";
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
   <title>CFI School updates</title>
   <meta name="Generator"     content="perl $]" />
-  <meta name="Author"        content="@{[scalar getpwuid $<]}" />
+  <meta name="Author"        content="$name" />
   <meta name="Description"   content="CSV diff @ARGV" />
   <style type="text/css">
     .rd { background:  #ffe0e0;        }
@@ -99,7 +100,7 @@ my @n   = map { $#{$f[$_]} } 0, 1;
 my @i   = (1, 1);
 my $hdr = "# csvdiff   < $ARGV[0]    > $ARGV[1]\n";

-$f[$_][1+$n[$_]][0] = $opt_n ? 2147483647 : "\xff\xff\xff\xff" for 0, 1;
+$f[$_][1+$n[$_]][0] = $opt_n ? 0x7FFFFFFF : "\xff\xff\xff\xff" for 0, 1;

 my %cls;
    %cls = (

If that works, I'll apply and commit that

x12340 commented 1 year ago

Thank you for your fast answer! In my tests the html support now works!

Best regards.

Tux commented 1 year ago

Part of the just uploaded 1.51