Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:
I've got to parse a string which contains variations on the following (along with some other stuff which I can ignore):
I need to extract those things, and I need to be sure the order they appear in, because if there's only one, it will be the large image, but if there are two, the second will be the thumbnail. It's a big ugly mess.
So far I'm doing this:
my @images = ( [], [] ); my ( $img_1_str, $img_2_str) = split( '\|', $str); @{ @images[0] } = $img_1_str =~ m/(\w+\.jpg)/gi; @{ @images[1] } = $img_2_str =~ m/(\w+\.jpg)/gi;
Which I think is foolproof, but I feel it's ugly and not particularly Perlish. Any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse messy string into neat data structure
by ikegami (Patriarch) on Aug 09, 2010 at 01:33 UTC | |
|
Re: Parse messy string into neat data structure
by Anonymous Monk on Aug 09, 2010 at 01:46 UTC | |
|
Re: Parse messy string into neat data structure
by mykl (Monk) on Aug 09, 2010 at 12:46 UTC | |
by Cody Fendant (Hermit) on Aug 10, 2010 at 02:53 UTC | |
|
Re: Parse messy string into neat data structure
by aquarium (Curate) on Aug 09, 2010 at 01:41 UTC | |
by Cody Fendant (Hermit) on Aug 09, 2010 at 01:57 UTC | |
by aquarium (Curate) on Aug 09, 2010 at 03:22 UTC |