Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: parse string containing space

by choroba (Cardinal)
on May 01, 2015 at 13:37 UTC ( [id://1125350]=note: print w/replies, xml ) Need Help??


in reply to parse string containing space

Build a parser. Marpa::R2 can help you with it:
#!/usr/bin/perl use warnings; use strict; use Marpa::R2; use Data::Dumper; my $input = q(name1=value1 name2=' value2=0' name3=value3); my $dsl = << '__DSL__'; lexeme default = latm => 1 :default ::= action => first List ::= Pair action => single | Pair white List action => store Pair ::= Key '=' Value action => pair Key ::= noneq Value ::= word | Quoted Quoted ::= quote string quote action => second noneq ~ [^=]+ word ~ [^\s]+ string ~ [^']+ white ~ [\s]+ quote ~ ['] __DSL__ sub first { $_[1] } sub second { $_[2] } sub single { [ $_[1] ] } sub pair { +{ $_[1] => $_[3] } } sub store { [ $_[1], @{ $_[3] } ] } my $grammar = 'Marpa::R2::Scanless::G'->new( { source => \$dsl } ); my $value_ref = $grammar->parse( \$input, 'main' ); print Dumper $value_ref;

Output:

$VAR1 = \[ { 'name1' => 'value1' }, { 'name2' => ' value2=0' }, { 'name3' => 'value3' } ];
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: parse string containing space
by mtovey (Initiate) on May 01, 2015 at 19:46 UTC

    Two good possibilities! I will try to test this weekend and see what shakes out.

    Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1125350]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found