in reply to Re: Parsing "=" separated output
in thread Parsing "=" separated output
Unfortunately, with the look-ahead you would miss the last entry in your example
Just put an alternation in the look-ahead to cope with end of string.
knoppix@Microknoppix:~$ perl -MData::Dumper -Mstrict -wE ' > my $str = > q{sometrash key1=value0 value1, value2 key2=value3 key3=value4}; > my %data = $str =~ m{([^\s=]+)=(.*?)(?=(?:\s+[^\s=]+=|\z))}g; > print Data::Dumper->Dumpxs( [ \ %data ], [ qw{ *data } ] );' %data = ( 'key2' => 'value3', 'key1' => 'value0 value1, value2', 'key3' => 'value4' ); knoppix@Microknoppix:~$
I hope this is of interest.
Update: I just realised this is in essence exactly the same as Utilitarian's reply. Please ignore.
Cheers,
JohnGG
|
|---|