hi,
i am doing a lookup using hash table. I have a pipe delimited file that i have to search for a new invocie number field by checking of an old invoice number-customer number key combination exists in hash:
sample input file:
===
1wwwwwwwwwwwwhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhh0
4wwwwwwwwww00002635168A0000C10139hhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhh9
===
sample lookup table rec:
ABC|C10139|35168A|2635168A-9z9866|5513975|2936554
DEF|C10139|956772|26956772-A05836|5513975|2936554
====
my code so far is as below:
===
open(INPUT,"<input_file") || die "Can't open lbx input file $input_file. $?\n";
while (<INPUT>)
{
chop;
$_ =~ s/#.*//; # strip comments
$_ =~ s/\s*$//; # remove trailing white space
$_ =~ s/^\s*//; # remove leading white space
next if ($_ =~ /^$/); # skip blank lines
$input_record = $_;
if (grep /^4/, $input_record)
{
$Invoice_record = $_;
$Full_invoice_number = substr($Invoice_record,11,12);
$District_identifier = substr($Invoice_record,15,2);
$invoice_number = substr($Invoice_record,17,6);
$customer_number = substr($Invoice_record,27,6);
open(LOOKUP,"<$Lookup_file") || die "Can't open lookup table $Lookup_file. $?\n";
while (<LOOKUP>)
{
chop;
$_ =~ s/#.*//; # strip comments
$_ =~ s/\s*$//; # remove trailing white space
$_ =~ s/^\s*//; # remove leading white space
next if ($_ =~ /^$/); # skip blank lines
my (@Lookup_record) = split '\|',$_;
$Path = $Lookup_record[0];
$CustomerNumber = $Lookup_record[1];
$InvoiceNumber = $Lookup_record[2];
$OraInvoiceNumber = $Lookup_record[3];
$OracustomerNumber = $Lookup_record[4];
$OraCustomeraccntNumber = $Lookup_record[5];
%Lookup_table = (
Path => "$OmdPath",
Customer_Number => "$CustomerNumber",
Invoice_Number => "$InvoiceNumber",
OraInvoice_Number => "$OraInvoiceNumber",
Oracustomer_Number => "$OracustomerNumber",
OraCustomeraccnt_Number => "$OraCustomeraccntNumber",
);
foreach $Customer_Number(keys %Lookup_table)
{
if ($Lookup_table{$Customer_Number} > 1)
{
print "duplicate";
print "count for duplicate user [$Customer_Number] is [$Lookup_table{$Customer_Number}]\n";
$duplicates = ($duplicates+($Lookup_table{$Customer_Number}-1));
print $duplicates;
}
}
}
close (LOOKUP);
next;
}
else
{
open(OUT,">>$modified_input_file") or die "Can't open output file $modified_input_file... $?\n";
print OUT "$input_record\n";
close OUT;
next;
}
}
close (INPUT);
=====
please advice!!!
regards,
Bhups