http://www.perlmonks.org?node_id=918183


in reply to Parsing "=" separated output

Hi Luke!

I assume your difficulty is to determine when the data ends and when the next key is coming. You could solve it with a look-ahead:

(?=\s[^\s]+=)

This looks for a blank and then some word followed by an = - according to your example that is your next key.

Unfortunately, with the look-ahead you would miss the last entry in your example, as there is no next key. But that can be solved easily by adding some dummy extension to the original string. So the following code works for me:

my $string = "sometrash key1=value0 value1, value2 key2=value3 key3=v +alue4"; $string .= " dummy="; # add a dummy value for the rege +x to work while ($string =~ m/\s+([^\s]+?)=(.*?)(?=\s[^\s]+=)/g) { $data{$1} = $2; }
HTH, Rata

PS.: please also read the node Death to Dot Star! to understand the risk in my altered solution