footbinc has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Im completely new to Perl and I was curious how using this file might work:
---------------------------- Contact_Name: Ben Cochrane Clinic_Name: Bens Clinic Billing_Address: 10728 - 56 Ave Street_Address: 10729 - 104 Ave ...... -------------------------------
That is the structure of the file (Value: Data) followed by a blank line between each value. I have a hash that I would like to fill in the values for
--------------------------------- %wrvars = { "CONTACT_NAME" => "", "CURRENT_DATE" => "", "CLINIC_NAME" => "", "CONTACT_NAME" => "", "CITY" => "", .... ---------------------------------
I would like to take the info from the file and fill in to the corresponding hash variable so that the has would become:
---------------------------------- %wrvars = { "CONTACT_NAME" => "Ben Cochrane", "CURRENT_DATE" => "Ben's Clinic", ... ----------------------------------
If somebody could please help me (Im not a programmer) it would be much appreciated. Thanks

Replies are listed 'Best First'.
Re: How Would this Input File Work?
by dimmesdale (Friar) on Jun 20, 2001 at 21:42 UTC
    Well, first you need to open the file. Then call a split and assign the hash accordingligly. Here goes (it's untested, but it should work):

    $IN = '/path/to/file'; open IN; while(<IN>) { next if /^$/; ($key,$value) = split /\s*:\s*/; $hash{uc $key} = $value; }
    If you wish to store multiple names in the same hash, however(for example, the file has many Contact_Names, you need to devise a better way, and need to decide what you want to sort by. One option would be to store on Contact_Name, assuming they are all unique. You could then make the contact_name key point to a reference to a hash, which would store the rest of the information. There are *many* different ways to do this and go about it, but it all depends on the data you are expecting.
      Your a brilliant man. Thanks :) Worked like a charm. Thanks again ben
Re: How Would this Input File Work?
by virtualsue (Vicar) on Jun 20, 2001 at 21:43 UTC
    Wellll, my consulting rates are reasonable, but I've got plenty of work already. You say you're not a programmer, but you're either going to have to make the attempt or hire someone. :)

    Please take a stab at it and then ask for help. There are Tutorials and a lot of code on this site that you can study in order to get started.