#!/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
In reply to Parse structured text using regex by trippledubs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |