assign pipe delimited file to hash??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhups
    New Member
    • Nov 2006
    • 1

    assign pipe delimited file to hash??

    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:

    ===
    1wwwwwwwwwwwwhh hhhhhhhhhhhhhhh hhhhhhhhhhhhhhh hhhhhhhhhhhhhhh hhhhhhhhhhhhhhh hhhh0
    4wwwwwwwwww0000 2635168A0000C10 139hhhhhhhhhhhh hhhhhhhhhhhhhhh hhhhhhhhhhhhhhh hhhh9
    ===

    sample lookup table rec:

    ABC|C10139|3516 8A|2635168A-9z9866|5513975| 2936554
    DEF|C10139|9567 72|26956772-A05836|5513975| 2936554

    ====


    my code so far is as below:

    ===

    open(INPUT,"<in put_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_n umber = substr($Invoice _record,11,12);
    $District_ident ifier = substr($Invoice _record,15,2);
    $invoice_number = substr($Invoice _record,17,6);
    $customer_numbe r = 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];
    $OraInvoiceNumb er = $Lookup_record[3];
    $OracustomerNum ber = $Lookup_record[4];
    $OraCustomeracc ntNumber = $Lookup_record[5];

    %Lookup_table = (

    Path => "$OmdPath",

    Customer_Number => "$CustomerNumbe r",

    Invoice_Number => "$InvoiceNumber ",

    OraInvoice_Numb er => "$OraInvoiceNum ber",

    Oracustomer_Num ber => "$OracustomerNu mber",

    OraCustomeraccn t_Number => "$OraCustomerac cntNumber",


    );



    foreach $Customer_Numbe r(keys %Lookup_table)
    {
    if ($Lookup_table{ $Customer_Numbe r} > 1)
    {
    print "duplicate" ;
    print "count for duplicate user [$Customer_Numbe r] is [$Lookup_table{$ Customer_Number }]\n";
    $duplicates = ($duplicates+($ Lookup_table{$C ustomer_Number}-1));
    print $duplicates;
    }
    }



    }
    close (LOOKUP);
    next;
    }
    else
    {
    open(OUT,">>$mo dified_input_fi le") 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
  • GunnarH
    New Member
    • Nov 2006
    • 83

    #2
    • Let Perl help you debug your script by including
      Code:
      use strict;
      use warnings;
      at the top, and declare the variables with my().
    • If necessary, post your debugged code within CODE tags.

    Good luck!

    Comment

    Working...