Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Using a Regex to parse into keys

by krusty (Hermit)
on Oct 07, 2002 at 02:06 UTC ( #203233=note: print w/replies, xml ) Need Help??


in reply to Using a Regex to parse into keys

The following example assumes these strings are sitting in a file somewhere,
that every instance of this search pattern has the possibility of more than one digit preceding the tilde,
and that there won't ever be an empty key.

{ local $/=undef; $string = <FILE>; #where FILE has been opened previously %colors = $string =~ /(\d+)~<font color="(.*?)"/ig; }
If your strings are sitting in an array, you could join the array $string = join '', @array;
If you data doesn't precisely match, it may be necessary to make it might be necessary to make the search pattern a little more general, but hope this helps for a start.

Cheers,
Kristina

Update: I didn't refresh to catch your replies before I hit submit, but ironically, this addresses your other concern, so it all works out in the end. This method is more efficient than a foreach loop.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://203233]
help
Chatterbox?
[choroba]: Yes, tried now. Login didn't show the login window at all, timed out, but worked for the second time instantly.
[choroba]: Trying the daemon log...
[choroba]: It seems very slow. But the internet is weird here in Vietnam...
[choroba]: again, stopping it and trying for the second time fixed the problem
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (13)
As of 2017-02-22 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (325 votes). Check out past polls.