Hi all. I'm new to perl, a new programmer, and I badly need guidance. I'm
trying to parse a config file with key/value pairs seperated by white space
and surrounded by curly brackets. It has multiple fields that look like
this:

{
Key  value
Key   value
}

My solution has been to parse it with something simple --

while ($file_contents =~ /(\w+)\s*\{([^}]*)\}/gs) {
       push @new, $2;
}

foreach (@new){
                  $_  =~ /\b(\w+)\s+(.*)\s+
                          \b(\w+)\s+(.*)/xgs;

My @next_tmp_variable = ($1, $2, etc);
}

-- but the config definitions contained in those curly brackets are
different lengths. Some only have a four left hand values, while others have
six or more. My solution isn't giving me what I really need.

So I have two questions. First, I don't understand how to test this so that
I parse all the values between the curly braces, regardless of how many
items are there. Second, and equally important, what kind of data structure
should I put the results in? I think I need a hash of hashes. What I'd like
to do is assign each left hand value as the key in a hash. Then, in each set
there's a left 'command' where the right hand value will always be unique,
which would be perfect for use as the name of an alias for the hash or as
the key to a reference to a hash of that definition. Is there a better way?
What's the best method for assigning all that stuff?

Thanks!



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to