#!/usr/bin/perl
use strict;
print "Hello!\n";
Main();
sub Main {
my @aFilename = ();
if(scalar(@ARGV) < 1){
print "Please enter filenames\n";
my $sFilein = <>; chop($sFilein);
@aFilename = split(' ',$sFilein);
}
else { @aFilename = @ARGV; }
print "Filenames given = @aFilename \n";
Checker(\@aFilename);
print "End Checker\n";
}
sub Checker { my $raFilename = shift;
my @aFilename = @$raFilename;
my @aAllFileID;
foreach(@aFilename){
my $raFileID = GetID($_,0);
push(@aAllFileID,$raFileID);
# PrintFileID($raFileID,$_);
}
my @aDataFilename = ("item_db.txt","item_db2.txt");
my @aDataID;
foreach(@aDataFilename){
my $raFileID = GetID($_,1);
push(@aDataID,@$raFileID);
# PrintFileID($raFileID,$_);
}
# PrintFileID(\@aDataID,"Data");
CompareID(\@aDataID,\@aAllFileID,\@aFilename);
}
sub CompareID{ my ($raDataID,$raAllFileID,$raFilename) = @_;
my $sI=0;
my @aFilename = @$raFilename;
foreach my $sCurfile (@aFilename){
print "Missing ID for $sCurfile \n:";
my $raFileID = $$raAllFileID[$sI];
my @aDataID = @$raDataID;
my @aFileID = @$raFileID;
my @aMissindID;
foreach my $sCurID (@aDataID){
my $sFound = 0;
# print "Searching $sCurID : ";
foreach(@aFileID){
if($sCurID == $_) { $sFound=1; last; }
}
if($sFound==0) {
push(@aMissindID,$sCurID);
# print " fail\n";
}
# else {
# print " foud\n";
# }
}
PrintFileID(\@aMissindID,$sCurfile);
print "\n\n";
$sI++;
}
}
sub GetID { my ($sFile,$sIsdata) = @_;
my @aFileID;
unless(-r "$sFile"){ print "Can't read/found $sFile\n"; next; }
open FILEHANDLE,"$sFile" or next;
my $sRegex;
if($sIsdata) { $sRegex = '\d+' }
else { $sRegex = '\d+#' }
foreach(<FILEHANDLE>){
if($_ =~ /^\/\//) {next; } #ignore comment
chomp($_);
if($_ =~ /$sRegex/){
if($sIsdata) {
my @aField = split(',',$_); #csv values
push(@aFileID,$aField[0]); #1st value
}
else {
my $sId = $_;
$sId =~ s/#//g;
push(@aFileID,$sId);
}
}
}
# PrintFileID(\@aFileID,$sFile);
return \@aFileID;
}
sub PrintFileID { my($raFileID,$sFilename) = @_;
print "ID for $sFilename:\n";
foreach(@$raFileID){
print "$_\n";
}
}