in reply to Re^2: removing reversed elements
in thread removing reversed elements

Okay. Try:

use Data::Dump qw[ pp ]; my @v = ([100, 200],[200, 300],[200, 100]);; my %uniq; my @r = grep{ ++$uniq{ join $;, $_->[0], $_->[1] } == 1 and ++$uniq{ join $;, $_->[1], $_->[0] } == 1 } @v;; pp @r;; ([100, 200], [200, 300])

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: removing reversed elements
by wind (Priest) on Feb 02, 2011 at 18:46 UTC
    This is nice but it misses the case where the pair of numbers is equal, as the first test will pass, but the second will fail. I believe this small modification will cover that case though
    use Data::Dump qw[ pp ]; my @v = ([100, 200],[200, 300],[200, 100], [200, 200]);; my %uniq; my @r = grep{ ++$uniq{ join $;, sort @$_ } == 1 } @v;; pp @r;; #([100, 200], [200, 300], [200, 200])
    - Miller
Re^4: removing reversed elements
by ramdat (Initiate) on Feb 02, 2011 at 10:12 UTC
    I am sorry..i am getting following error message:

    Can't locate Data/Dump.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 .) at test.pl line 1. BEGIN failed--compilation aborted at test.pl line 1.

    The code is very high level to people like me..if you would not mind, could you comment it please..

      Data::Dump is just to dump out the array, so you could see, that the function does what you want. You could omit using it and pp-line too.

      AFIU grep here triggers counters, so it can throw away pairs already seen.

Re^4: removing reversed elements
by raybies (Chaplain) on Feb 02, 2011 at 14:11 UTC
    Browser: Once again, your solution is a thing of beauty. I bow to your perliness.