diff options
author | Joey Hess <joey@kitenet.net> | 2012-04-09 16:18:21 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-04-09 16:18:21 -0400 |
commit | bbfa7f9a5d262d13c825005f89410f464148fd1d (patch) | |
tree | e649f85402c45a6a932605f063525d660704307b | |
parent | b70bf8f3b34e03acfe4ed906929e1a3f2b42dd4b (diff) | |
download | moreutils-bbfa7f9a5d262d13c825005f89410f464148fd1d.tar.gz |
combine: Avoid reading files twice, to support data coming from pipes. Closes: #667960 Thanks, Carsten Hey
-rwxr-xr-x | combine | 29 | ||||
-rw-r--r-- | debian/changelog | 2 |
2 files changed, 28 insertions, 3 deletions
@@ -104,9 +104,32 @@ sub compare_or { sub compare_xor { my ($file1, $file2) = @_; - - compare_not($file1, $file2); - compare_not($file2, $file1); + + my ($lines2, $seen2) = ([], {}); + filemap $file2, + sub { + push @$lines2, $_; + $seen2->{$_} = 1; + }; + + filemap $file1, + sub { + # Print all lines in file1 that are not in file2, + # and mark lines that are in both files by setting + # their value in %seen2 to 0. + if (exists $seen2->{$_}) { + $seen2->{$_} = 0; + } + else { + print "$_\n"; + } + }; + + foreach (@$lines2) { + # Print all lines that are in file2 but not in file1. + # The value of these lines in seen2 is set to 1. + print "$_\n" if $seen2->{$_}; + } } sub compare_not { diff --git a/debian/changelog b/debian/changelog index 13822c1..cd406ff 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,8 @@ moreutils (0.46) UNRELEASED; urgency=low * Typo. Closes: #649158 + * combine: Avoid reading files twice, to support data coming from + pipes. Closes: #667960 Thanks, Carsten Hey -- Joey Hess <joeyh@debian.org> Fri, 18 Nov 2011 13:37:10 -0400 |