Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use File::Basename;
- use Getopt::Long;
- my $sItem_db_re = "db/re/item_db.txt";
- my $sItem_db_pre = "db/pre-re/item_db.txt";
- Main();
- sub Main {
- my($filename, $dir, $suffix) = fileparse($0);
- chdir $dir;
- chdir ".."; #put ourself like was called in main folder
- GetArgs();
- my %hDB_re_ID;
- my %hDB_pre_ID;
- my $nb_columns = 22;
- my $line_format = "([^\,]*),"x($nb_columns-3)."(\{.*\}),"x(2)."(\{.*\})"; #Last 3 columns are scripts.
- ParseItemDBFile($sItem_db_re,\%hDB_re_ID,$line_format);
- ParseItemDBFile($sItem_db_pre,\%hDB_pre_ID,$line_format);
- #DisplayIDFound("RE",\%hDB_re_ID);
- #DisplayIDFound("pRE",\%hDB_pre_ID);
- SearchAndDisplayMissing("RE","pRE",\%hDB_re_ID,\%hDB_pre_ID);
- SearchAndDisplayMissing("pRE","RE",\%hDB_pre_ID,\%hDB_re_ID);
- }
- sub GetArgs {
- my $sHelp;
- GetOptions(
- 'dbre=s' => \$sItem_db_re, #re item db file
- 'dbpre=s' => \$sItem_db_pre, #pre item db file
- 'help!' => \$sHelp,
- ) or $sHelp=1; #display help if invalid option
- if( $sHelp ) {
- print "Incorect option specified, available option are:\n"
- ."\t --dbre filename => specify wich item re db file to use\n"
- ."\t --dbpre filename => specify wich item pre db file to use\n";
- exit;
- }
- }
- sub DisplayIDFound { my ($sFilename,$rHash) = @_;
- my @aDB_ID = keys %$rHash;
- print "Found $sFilename = [ @aDB_ID ] \n";
- }
- sub ParseItemDBFile { my ($sFilename,$rHash,$sLine_format) = @_;
- open FILE, "<$sFilename" or die "couldn't open file $sFilename \n";
- while(my $ligne=<FILE>){
- if ($ligne =~ /^\s*$/ ) { next; } #skip empty line
- if ($ligne =~ /[^\r\n]+/) {
- $ligne = $&;
- if ($ligne =~ /^\/\//) {
- #print "Comment line founded : $ligne \n";
- next;
- }
- if ($ligne =~ $sLine_format) {
- my @champ = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22);
- $$rHash{$1} = $ligne;
- }
- }
- }
- close FILE;
- }
- sub SearchAndDisplayMissing { my($sNameSrc,$sNameChk,$rhSrc,$rhChk) = @_;
- print "Checking ID from $sNameSrc are into $sNameChk \n";
- my $sCount = 0;
- my %hChkData = %$rhChk;
- my %hSrcData = %$rhSrc;
- my @aListID = keys %hSrcData;
- foreach my $sID(@aListID){
- unless($hChkData{$sID}){
- print "Didn't found in $sNameChk => ID : ".$sID." with line ".$hSrcData{$sID}." \n\n";
- $sCount++;
- }
- }
- unless($sCount){
- print "No missing ID found \n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement