in reply to using lookaround assertions to grab info
my @lines = split /\n/, $m; my %m; my $curr_index; foreach my $line (@lines) { $line =~ /^\s*(\w+)?\s*:\s*(.*)$/; next unless $1 || $2; unless (defined $curr_index) { die "First line doesn't have a key\n" unless $1; $m{$1} = $2; $curr_index = $1; next; } if ($1) { $m{$1} = $2; $curr_index = $1; next; } $m{$curr_index} .= "\n$2"; }
Untested, but it should work.
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: using lookaround assertions to grab info
by punkish (Priest) on Jun 04, 2004 at 02:45 UTC | |
by dragonchild (Archbishop) on Jun 04, 2004 at 12:48 UTC |