in reply to Re: Parsing Challenge
in thread Parsing Challenge

Some of the keys have multiple values, though. You could remember the last key...
foreach (split " ", $data) { if (/^([^=]*)=(.*)/) { $hash{$last=$1}=$2 } elsif (defined $lastkey) { $hash{$last} .= " $_" } }
Since "key=" is easy to recognize, another way would be to use split:
%hash = ("JUNK", split /([^=\s]*)=/, $data)
if you don't mind the JUNK, that is.

Replies are listed 'Best First'.
Re: Re: Re: Parsing Challenge
by blue_cowdawg (Monsignor) on May 24, 2001 at 22:39 UTC

    What if the literal "key" is not always present? What if the pairs become:

    my $data="fruit=apple meat=steak ....";


    Peter L. BergholdSchooner Technology Consulting, Inc.
    Peter@Berghold.Netwww.berghold.net