The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Parse::Yapp::KeyValue - parser for simple key/value pairs


parse a string of simple key/value pairs and store the results in a hash reference for easy access. Parse::KeyValue correctly handles escaped quotes as well as escaped backslashes.

Parse::KeyValue will parse the following example string:

     AL=53 AK=54 AB=55 TN="home sweet home" =$

into a hashref with the following contents:

         ''   => '$',
         'AL' => '53',
         'TN' => 'home sweet home',
         'AK' => '54',
         'AB' => '55'

multiple identical keys are treated as arrays. the string

     A=1 A=2 A=3

will return a hash reference with the following contents:

     { A => [ 1, 2, 3 ] }

tokens without an associated key name will be treated as pairs with an empty string for the key. the string

     yeah alabama "crimson tide"

will return a hash reference with the following contents:

     { '' => [ 'yeah', 'alabama', 'crimson tide' ] }


 my $str  = 'A=1 K=2 B=3 A=4';
 my $kv   = new Parse::Yapp::KeyValue;
 my $href = $kv->parse($str);

 print $href ? Dumper $href : "parse failed\n";


 - configurable delimiter
 - flags to alter behavior in the event of
   multiple keys (error, overwrite last value,
   keep first value)
 - flag to require ALL values be inside an array
   reference, not just keys with multiple values



instantiates a new Parse::Yapp::KeyValue object. no arguments are currently accepted.


parses the supplied string and returns a hash reference containing the parsed data. in the even that parsing fails, undef is returned.


mike eldridge <>


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.