techlearner has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to find and print duplicte elemets in multi dimensional array
by moritz (Cardinal) on Dec 13, 2010 at 15:06 UTC | |
|
Re: How to find and print duplicte elemets in multi dimensional array
by VinsWorldcom (Prior) on Dec 13, 2010 at 15:28 UTC | |
by techlearner (Initiate) on Apr 27, 2011 at 05:07 UTC | |
by Anonymous Monk on Apr 26, 2011 at 12:08 UTC |