Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Regex question

by dreadpiratepeter (Priest)
on Jul 21, 2009 at 13:12 UTC ( [id://781952]=note: print w/replies, xml ) Need Help??


in reply to Regex question

Assuming that there are no commas in your data other than those separating the params, I would split the lines on /\s*,\s*/, which would give you an array of your parameters, then loop through the parameters and match each of them. ie (warning, untested code)
while (<>) { my @params = split /\s*,\s*/; foreach my $param (@params) { $param =~ /(Identities|Positives|Negatives)\s+=\s+(.+)\s+\((.+)\%\ +)/; # $1 now contains which type you matched, $2 and $3 are the submat +ches, do what you will with them } }
or you could get fancier and do:
while (<>) { my %params = map { my ($k,$v) = split /\s*=\s*/; $v =~ /(.+)\s+\((.+)\%\)/; ($k => [$1,$2]) } split /\s,\s*/; }
and get a hash of all your params in one fell swoop.


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://781952]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found