- Nagios - Switch Interface Traffic
- How To - Linux Server Performance
- Notes - Building New ESXi Host for iSCSI with Jumbo Frames
- Microsoft Office Version Numbers (XP, 2003, 2007, 2010)
- ESXi Custom Welcome Screen Text
- PHP - Read Data from a CSV file
- PHP - Input Variables from URL
- Fix - WMI Error EventID 10
- Fix - EventID 4007 DNS Server Error
- FIX - CHECK_ESX3.PL Script
Perl Array Comparison
- References:
Here's a great example for an array comparison mechanism in perl to find out what is in common, what is different, etc.
$ cat ./compare_array.pl
#!/usr/bin/perl
use strict;
use warnings;
my @array1;
my @array2;
my @diff;
my @isect;
my $item;
my %count;
@array1 = (1, 2, 4, 6, 7, 8);
@array2 = (1, 2, 3, 5, 6, 7);
@isect = ( );
@diff = ( );
%count = ( );
foreach $item (@array1, @array2) { $count{$item}++;}
foreach $item (keys %count) {
if ($count{$item} == 2) {
push @isect, $item;
} else {
push @diff, $item;
}
}
print "\nA Array = @array1\n";
print "\nB Array = @array2\n";
print "\nIntersect Array = @isect\n";
print "\nDiff Array = @diff\n\n";
exit 0;
$ ./compare_array.pl
A Array = 1 2 4 6 7 8
B Array = 1 2 3 5 6 7
Intersect Array = 6 1 7 2
Diff Array = 8 4 3 5
- Printer-friendly version
- Login to post comments
-
