D
DJ Stunks
I whipped this up for someone looking for a parser for the DATA listed.
It works well, but I can't figure out why the split() produces an empty
leading field... I ran it through re qw{ debug } but I couldn't pick
it up.
Can anyone shine some light on this for me?
TIA,
-jp
#!/usr/bin/perl
use strict;
use warnings;
my $text = do {local $/; <DATA>};
my %hash;
(undef, %hash) = split m{^ (.+?) \s* : \s* }xm, $text;
s/\s+/ /g and s/\s+$//g for values %hash; # repair whitespace
use Data:
umper;
$Data:
umper::Sortkeys = 1;
print Dumper \%hash;
__DATA__
keyword1: blahblah
asdfas
keyword2: blah blah blah
more blah blah blah
keyword3: and so on
and on to in the end
three lines total
It works well, but I can't figure out why the split() produces an empty
leading field... I ran it through re qw{ debug } but I couldn't pick
it up.
Can anyone shine some light on this for me?
TIA,
-jp
#!/usr/bin/perl
use strict;
use warnings;
my $text = do {local $/; <DATA>};
my %hash;
(undef, %hash) = split m{^ (.+?) \s* : \s* }xm, $text;
s/\s+/ /g and s/\s+$//g for values %hash; # repair whitespace
use Data:
$Data:
print Dumper \%hash;
__DATA__
keyword1: blahblah
asdfas
keyword2: blah blah blah
more blah blah blah
keyword3: and so on
and on to in the end
three lines total