in reply to Sorting By Column
Read the files line-by-line, split each pair of lines along whitespace, compare the relevant field, and output the lines if they differ:
#!/usr/bin/perl use feature qw/say/; use warnings; use strict; open my $file1, "<", "test1.txt" or die "Could not open first file: $! +\n"; open my $file2, "<", "test2.txt" or die "Could not open second file: $ +!\n"; while(my $line1 = <$file1>) { my $line2 = <$file2>; chomp ($line1, $line2); my ($key1, $num1, $str1) = split /\s+/, $line1; my ($key2, $num2, $str2) = split /\s+/, $line2; if($str1 ne $str2) { say $line1; say $line2; } } close $file1 or die "Could not close first file: $!\n"; close $file2 or die "Could not close second file: $!\n";
There's bound to be shorter, more idiomatic ways of achieving the same thing, but since your userpage indicates you're still new to Perl, you may find this the most instructive/useful.
On an unrelated side note, could you edit your post to use <code> tags for your sample data? See the following nodes for more information on formatting etc.:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting By Column
by dasgar (Priest) on Jul 10, 2014 at 19:02 UTC | |
by AppleFritter (Vicar) on Jul 10, 2014 at 19:05 UTC | |
by Roguehorse (Initiate) on Jul 10, 2014 at 21:12 UTC | |
|
Re^2: Sorting By Column
by Roguehorse (Initiate) on Jul 10, 2014 at 22:21 UTC | |
by AppleFritter (Vicar) on Jul 11, 2014 at 00:27 UTC |