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

No sorry..actually i meant that (100 200) pair and (200 100)pair are both same for me..so i want only either (100 200) or (200 100)pair in the output.So if i have elements (X Y) it is same as (Y X) too..I need only one pair from the both..it can be any thing...

Replies are listed 'Best First'.
Re^3: removing reversed elements
by BrowserUk (Patriarch) on Feb 02, 2011 at 09:56 UTC

    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.
      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
      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.

      Browser: Once again, your solution is a thing of beauty. I bow to your perliness.