Hello,
I am hoping for your help with what should be quite a simple problem, but I am having issues. I have a large dataset showing connections between individuals in a community. What I am trying to do is print out only the data on unreciprocated connections. So, in the example below, I would not want the first two lines because personA and personB have a reciprocal connection. But I would want the final three lines because the connection only goes one way.
I used the following script and thought that the second "if clause" would mean that instances such as the personA and personB pairing (i.e. the first two lines) were not printed, but instead it prints all of my data lines.
I imagine that the solution will be very simple, but I keep going round in circles without getting anywhere, and a second pair of eyes would be very helpful.use strict; use warnings; while(<DATA>) { my $comment_author1; my $comment_author2; my $interactions; if( $_ =~ /(.*?),(.*?),(.*?)$/gm) { $comment_author1 = $1; $comment_author2 = $2; $interactions = $3; if( $_ =~ "$comment_author2,$comment_author1") { print "no match\n"; } else { print "$comment_author1,$comment_author2,$interactions\n"; } } } __DATA__ personA,personB,10 personB,personA,190 personA,personC,23 personA,personD,43 personE,personF,10
Thank you!
In reply to print lines which are not reverse duplicates by Maire
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |