in reply to printing the first column when both columns 2 and 3 are the same
If I understand what you are saying, you want to print when you get a match on both columns, but in your original code you are only keeping track of column 2. I would use a HASHES OF HASHES structure, with
where I have modified the classic code to remove duplicates from How can I remove duplicate elements from a list or array? in perlfaq4.open my $FH2, '<', '/tmp/fileread' or die "unable to open file 'file' +for reading : $!"; open my $FH6, '>', '/tmp/tst.txt' or die "unable to open file 'file' f +or reading : $!"; my %duplicates; while (<$FH2>) { chomp; my ($column_1, $column_2, $column_3) = split /,/; print {$FH6} "$column_1\n" if $duplicates{$column_2}{$column_3}++; } close $FH6; close $FH2; open my $fh, '<', '/tmp/tst.txt' or die "unable to open file 'file' fo +r reading : $!"; while (my $line = <$fh>) { print $line; } close $fh;
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|