[ILUG] [OT] perl question...

Declan Grady Declan.Grady at nuvotem.com
Fri Jul 16 14:00:56 IST 2004


Niall O Broin wrote:

>On Thursday 15 July 2004, Declan.Grady at nuvotem.com (Declan Grady) wrote:
>  
>
>Did I mention the arrays?
> Erm.. I don't recall :)
>  
>
>>so.. how do I fill up the hash from my custname ascii file ?
>>    
>>
>Well, the simplest way of doing this is to have 6 hashes (not the most perly
>way, but probably the easiest way to understand and remember the perl mantra -
>TIMTOWTDI ) which are called code, name, ref, t, val, date, rate, f, paid (I
>left out d1_ and d3_ to make names shorter - leave them if you want. Then read
>your flat files into the hashes by reading them line by line (obviously
>skipping the first two lines) and using perl's split function to split them up
>into their separate values and then putting each of those values into the
>appropriate hashes, keyed by the code.
>
>Is that getting you anywhere?
>  
>
Yes.. I think I've cracked it. I'm only using one hash of the code & name.
I'm reading in the customer names from the file as follows:

open(IN,"<co2_0101.txt") or die "cant open 101.txt\n";
%names={};
while (<IN>) {
    # Parse the file
    if ($_ =~ "d1_code ") {
        # Ignore it
    } elsif ($_ =~ "=========") {
        # Ignore it
    } elsif ($_ =~ "End of file") {
        # Ignore it
    } else {
       # Want this line, so parse it
       $account = substr $_, 0 ,10;
       $account =~ s/\ //g;
       $name    = substr $_,11 ,30;
       # Get rid of any commas from the name, for the csv file
       $name =~ s/\,/\./g;
       $names{$account}=$name;

#DEBUG  print "$account $name\n";
    }

}
.. Then while reading the openitems file, once I get the account
I can reference the customer name using  $names{$accountcode}

Excellent.

Thanks for your help.... much appreciated.

Declan



More information about the ILUG mailing list