On Thursday 15 July 2004, Declan.Grady at nuvotem.com (Declan Grady) wrote:
>>>I have two arrays, @openitems, and @customernames.
Unless there's something you haven't mentioned, I don't see why you need these
arrays at all.
>I have an array of strings - I read the array from a fixed-width ascii
>file, so my array would be :
>@openitems[1]="d3_code d3_ref t d3_val d3_date d3_rate f
>d3_paid"
>@openitems[2]="========== ========== = ========== ======== ========== =
>=========="
>@openitems[3]=" 10130 1509 A 53.07000 20030430
>1.00000 0.00000"
>I then have a similar array for the customer names:
>>@custname[1]="d1_code d1_name "
>@custname[2]="========= =============================="
>@custname[3]=" 10166 Customer Name A "
>Does this mean I can have a hash of the customer names, and reference
>the element in the hash by the customer code from the openitems array ?
Yes, but as mentioned above, forget the arrays.
>- Or am I way off the point.
Did I mention the arrays?
>i.e. Somehow automate putting the file into a custnmae hash:
>%custname = ( 10166 => "Customer Name A", 10170 => "Customer Name B" ...
>etc );
>>Then get the customer name from
>$this_customer="10167";
>print $custname{ $this_customer };
>>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?
Niall
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!