in reply to print lines which are not reverse duplicates

Hi, here's one way*:

use strict; use warnings; use feature 'say'; my %keep; for my $line ( <DATA> ) { chomp $line; my ( $P1, $P2, $I ) = split /,/, $line; $keep{"$P1$P2"} = $line; if ( $keep{"$P2$P1"} ) { delete $keep{"$P2$P1"}; delete $keep{"$P1$P2"}; } } say for values %keep; __DATA__ personG,personH,42 personA,personB,10 personB,personA,190 personA,personC,23 personA,personD,43 personE,personF,10
Output:
$ perl 1226286.pl personG,personH,42 personE,personF,10 personA,personD,43 personA,personC,23
... add sorting etc. as you wish ...

Hope this helps!

(*Disclaimer: pre-coffee!)


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: print lines which are not reverse duplicates
by Maire (Scribe) on Nov 26, 2018 at 08:02 UTC
    Thank you very much!