#!/usr/bin/perl
# Written by Myst Shen, Aug.28, 2008
# Last modified on Dec. 23, 2008
use strict;
use Term::ANSIColor;
my ($sn, @arr1, @arr2, @arr3, @arr4, @arr5, $num);
print "Enter a serial number, please.\n";
$sn = <stdin>;
chomp($sn);
while (<>) {
if (/$sn/) {
push (@arr1, $_);
} else {
push (@arr2, $_);
}
}
sub by_this {
my @x = split (/\s+/, $a);
my @y = split (/\s+/, $b);
$x[3] cmp $y[3];
$x[4] cmp $y[4];
$x[5] cmp $y[5];
}
@arr3 = sort by_this @arr1;
@arr4 = reverse @arr2;
@arr5 = @arr3;
$num = 1; print color 'yellow'
;
print "----------------------------------------------------------------\n"; print color 'reset'
;
L:foreach my $i (@arr3) { print color 'red'
;
print $i; print color 'reset'
;
shift @arr5;
my @p = split (/\s+/, $i);
my @q = split (/\s+/, $arr5[0]) if (@arr5);
if (@p && @q && $p[3] eq $q[3] && $p[4] eq $q[4] && $p[5] eq $q[5]) {
next L;
} else {
foreach my $j (@arr4) {
print color 'reset';
my @x = split (/\s+/, $i);
my @y = split (/\s+/, $j);
if (@x && @y) {
if ($x[3] eq $y[3] && $x[4] eq $y[4] && $x[5] eq $y[5]) {
$num *= -1;
$num == -1 ? print color 'green' : print color 'bold green';
print $j;
}
}
} print color 'yellow'
; print "----------------------------------------------------------------\n";
print color 'reset'
; } }
print color 'yellow'
;
print "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n";
print color 'reset'
;
print "\n";
|