trippledubs has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; sub parse { my $text = shift; my $values; my $reg = qr/ ([A-Z]+) #Capital letters \n? #Possible new line \| #Literal | (?: #Begin key value pairs \|?(.*?) #Key = (.*?) #Value \| #Begins new kv pair )+ /xs; while ( $text =~ m/$reg/g ) { print "Match!\n"; print $text; push @{$values->{$1}}, { $2 => $3 }; } return $values; } my $text = join '', <DATA>; my $values = parse($text); print Dumper $values; #not what I want __DATA__ CAR MODEL|name=Mustang|Quality=A|Speed= MODEL|Chevy=Cavalier|MPG=20 MODEL |Color=blue|type=hatchback|crashrating=spectacular |explodes=true|speed=|storage=none,little
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse structured text using regex
by kcott (Archbishop) on Mar 17, 2014 at 07:26 UTC | |
by trippledubs (Deacon) on Mar 17, 2014 at 19:18 UTC | |
|
Re: Parse structured text using regex
by Anonymous Monk on Mar 16, 2014 at 20:52 UTC | |
by trippledubs (Deacon) on Mar 17, 2014 at 04:21 UTC | |
by kcott (Archbishop) on Mar 17, 2014 at 05:42 UTC | |
by trippledubs (Deacon) on Mar 17, 2014 at 19:17 UTC | |
by kcott (Archbishop) on Mar 17, 2014 at 22:55 UTC |