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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.