[Aberdeen-pm] Quick perl fix needed

Gavin Henry ghenry at perl.me.uk
Fri Mar 10 14:43:01 PST 2006


<quote who="znx">
> Not pretty.. I'm sure there is a better way..
>
> ------
> $_ = "<blah key=value key2=value2 keyX=valueX keya=\"test\" keyc='wee'/>";
>
> foreach(split(' ([\w="\']+)')) {
> 	if(/=/) {
> 		($a, $b) = split(/=/);
> 		$array{$a} = $b;
> 	}
> }
>
> print $array{'keya'};

This is a hash, not an array ;-)

Use http://search.cpan.org/dist/XML-Simple/ for proper parsing that is
tried and tested.

> ----
>
> M
> On 10/03/06, Mark McRitchie <mark at arricc.net> wrote:
>> Heyas,
>>
>> I need to convert a string in the form:
>> <blah key=value key2=value2 ... keyX=valueX/>
>>
>> Into an associative array eg:
>> arr(key)=value
>> arr(key2)=value2
>>
>> Is there a quick way to do this? Yes its an XML string, but I want to do
>> it without having to use any extra packages...
>>
>> Cheers!
>> Mark.
>> _______________________________________________
>> Aberdeen-pm mailing list
>> Aberdeen-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/aberdeen-pm
>>
> _______________________________________________
> Aberdeen-pm mailing list
> Aberdeen-pm at pm.org
> http://mail.pm.org/mailman/listinfo/aberdeen-pm
>



More information about the Aberdeen-pm mailing list