To add to moritz suggestion of a hash above, couldn't you do the whole thing in just one script? You don't need to sort if you use a hash so it becomes much simplier.

For example:

#!/usr/bin/perl use strict; use warnings; my %dup; while (<DATA>) { my @tmp = split /,/; if (exists($dup{$tmp[6]}{$tmp[4]})) { print "DUPLICATE!\n Device: $tmp[6]\n Policy: $tmp[4]\n\n" } else { $dup{$tmp[6]}{$tmp[4]} = 1 } } __DATA__ 4778228,0,0,,Policy_name1,Incremental,Device_name1, ,1291910125,000000 +0053,0000000000, ,1 ,,,,,0,,root,0,13,1,99998,root,x,1,30,0,0,0,0,0,4 +778228,,,,,,,,,,,,,0,0,1,0,0,,0,,,,Max 4778228,0,0,,Policy_name2,Incremental,Device_name2, ,1291910125,000000 +0053,0000000000, ,1 ,,,,,0,,root,0,13,1,99998,root,x,1,30,0,0,0,0,0,4 +778228,,,,,,,,,,,,,0,0,1,0,0,,0,,,,Max 4778228,0,0,,Policy_name3,Incremental,Device_name3, ,1291910125,000000 +0053,0000000000, ,1 ,,,,,0,,root,0,13,1,99998,root,x,1,30,0,0,0,0,0,4 +778228,,,,,,,,,,,,,0,0,1,0,0,,0,,,,Max 4778228,0,0,,Policy_name2,Incremental,Device_name2, ,1291910125,000000 +0053,0000000000, ,1 ,,,,,0,,root,0,13,1,99998,root,x,1,30,0,0,0,0,0,4 +778228,,,,,,,,,,,,,0,0,1,0,0,,0,,,,Max

Output:

C:\> test.pl DUPLICATE! Device: Device_name2 Policy: Policy_name2

In reply to Re: How to find and print duplicte elemets in multi dimensional array by VinsWorldcom
in thread How to find and print duplicte elemets in multi dimensional array by techlearner

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.