On 6/24/2004 4:58 PM, Price, Jason (TLR Corp) wrote:
----Original Message---- From: Gunnar Hjalmarsson [mailto:[EMAIL PROTECTED] Sent: Thursday, June 24, 2004 3:46 PM To: [EMAIL PROTECTED] Subject: Re: RegExp help
Jason Price wrote:
I'm trying to write a regular expression to divide up a line of text
into a hash, but am having a hard time with it. I'm hoping you all
can help me.
Here's an example line of text:
<example snipped>
Not every line will have the same keys, or the same number of keys.
In that case the example you posted is obviously not sufficient as a
problem description.
Is there a good way to do this with a regular expression?
Can't tell.
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
Basically, every line will follow a similar pattern: "junk KEY1 value1 KEY2 value2 KEY3 'value 3 here'". Each word that is all caps is a key, and text between that key and the next is the value for that key. The problem is that one line may have 2 key/value sets, while the next has 4 sets.
Here's 2 lines from the file, demonstrating differences:
"( uiwgAttribute-OID NAME 'uiwgAttribute' DESC 'Contains meta data about an attribute' SUP top MUST cn MAY ( uiwgADsType $ uiwgDescription $ uiwgDisplayName $ uiwgIsMultiValued ) )
( wgDestination-OID NAME 'wgDestination' SUP top MUST cn MAY wgURI )"
After each line is evaluated, I want a hash with the key/value pairs for that line.
Does that clarify at all?
You might give the core module Text::ParseWords a try. Your data looks like it is formatted as: key [space] quoted_value [space]... So the results of Text::ParseWords can be assigned directly to a hash.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>