Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regular expressions - match

by eff_i_g (Curate)
on Jan 24, 2011 at 22:31 UTC ( [id://884015]=note: print w/replies, xml ) Need Help??


in reply to Regular expressions - match

For CSV data see Text::CSV.

Here's a simple example using regex:
use warnings; use strict; my $string1 = "one=1,two=2,three=3,four=4,five=5"; my $string2 = "one=1,three=3,five=5"; for ($string1, $string2) { print "$_\n"; print "$1=$2\n" while /(\w+)=(\d+)/g; }
You can modify the RE as you see fit and/or put the data in a hash.

Update/FYI: Your RE does not work because the .*'s are greedy.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found