Hi,

I am beginner in PERL , I am trying to write a script which will find duplicate elements in multi dimensional array.

My array is o/p of a backup jobs summary which contains device names and backup polices, I want to find duplicate jobs with respect to devices and backup policy names simply finding jobs which have same device name and same policy name.

First I sorted the array with device names then tried to compare each device policy name with it's next row and print row whih are whaich has same elements for device na dpolicy.

Her is code for sorting w.r.t device name which is 7th element

#!/usr/bin/perl while (<>) { @tmp = split(/,/); push @failures, [ @tmp ]; } @sorted = sort { $a->[6] cmp $b->[6] } @failures; for $array_ref ( @sorted ) { print "@$array_ref \n" ;

o/p of this script goest another script which finds duplicate devic enad policy names 5th elemt is policy name

#!/usr/bin/perl while (<>) { @tmp = split; push @failures, [ @tmp ]; } $konst = $failures[0]; for $i ( 0 .. $#failures ){ for $j ( 0 .. 6 ) { if ( $i == 0 ) { if ( $konst->[4] eq $failures[$i+1][4] && $konst->[6] eq $failure +s[$i+1][6] ) { print "\t$failures[$i][$j]"; $konst = $failures[$i+1]; ; } } elsif ( $konst->[6] eq $failures[$i+1][6] && $konst->[6] eq $failures[ +$i+1][6] ) { print "\t$failures[$i][$j]"; $konst = $failures[$i+1]; ;} } print "\n";
}

but I ma not getting desired o/p I feel logic is correct please help me or guide if there is any better way of doing it in PERL

File contents are like this, it is example how each line looks like in after sorting w.r.t device name

4778228,0,0,,Policy_name,Incremental,Device_name, ,1291910125,0000000053,0000000000, ,1 ,,,,,0,,root,0,13,1,99998,root,x,1,30,0,0,0,0,0,4778228,,,,,,,,,,,,,0,0,1,0,0,,0,,,,Max

Thanks, TechLearner


In reply to 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.