Hey all,

My sincerest apologize to all!  The last post has does exactly what I
want it to do.  There is no need have to do anything else at all with
the code.  Trial and error :)

Regards,

Dan

Hey all,

[Config File]
Linux Passwd File             = /etc/passwd
New File                                = /home/test
Old File                          = /home/test
Company Name                  = Company Name
Company URL                   = http://www.servername.com

Above is a config file I just created.  I want perl to be able to read
all the valus of this file into a hash.  Now I can do this no problem
with the following code...

$file = '/home/config';

sub read_config {
    open FILE, "$file" or die "cannot open '$file': $!\n";
      while( <FILE> ) {
        $CONFIG_NAME = $1 and next if /^\s*\[\s*(.*?)\s*\]\s*$/;
        next unless defined $CONFIG_NAME && /^\s*(.*?)\s*=\s*(.*?)\s*$/;
        $CONFIG{$CONFIG_NAME}{$1} = $2;
      }
      close FILE;
      return %CONFIG;
}

As we all know :)  this will return the hash (%CONFIG) in the form of...

%CONFIG = (
             'Config File => {
                                        'Linux Passwd File'           =>
'/etc/passwd',
                                                'New File'
=> '/home/test',
                                                'Old File'
=> '/home/test',
                                                'Company Name'
=> 'Company Name',
                                                'Company URL'
=> 'http://www.servername.com'
                        },
           )

Now if the cofig file looked like this....

[   Config File     ]
Linux Passwd File             = /etc/passwd
    New File                            = /home/test
   Old File                       = /home/test
Company Name                  = Company Name
  Company URL                   = http://www.servername.com

Then the scrip would still return the correct hash like so....

%CONFIG = (
             'Config File => {
                                        'Linux Passwd File'           =>
'/etc/passwd',
                                                'New File'
=> '/home/test',
                                                'Old File'
=> '/home/test',
                                                'Company Name'
=> 'Company Name',
                                                'Company URL'
=> 'http://www.servername.com'
                        },
           )

..... but what I need to know is if It is possible for the code above to
be manipulated in such a way where I or the user could write the config
file in the following way...


#This is the Config File Name
[Config File]
#This is the Linux password file
#Please make sure this is correct
Linux Passwd File             = /etc/passwd

New File                                = /home/test
Old File                          = /home/test
   Company Name                  = Company Name
Company URL                   = http://www.servername.com

So in other words I still want to be able to exactly what I can do now
but also place a # (comment) any where in the script and then have the
code completly ignore it.  I also wna tto be able to place a new line or
2 or 3 in the code and have the code completly ignore it.

Is this possible?

Kind regards,

Dan

==============================
VINTEK CONSULTING PTY LTD
(ACN 088 825 209)
Email:  [EMAIL PROTECTED]
WWW:    http://www.vintek.net
Tel:    (08) 8523 5035
Fax:    (08) 8523 2104
Snail:  P.O. Box 312
        Gawler   SA   5118
==============================


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to