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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |