in reply to Matching over multiple lines in a scalar
Why use negative-width assertions, when you're already using the /m flag? I like this:
use Data::Dumper; my $info = do { local $/; <DATA> }; my %lines; while($info =~ m/(\d+)\: (.+?)$/gm) { $lines{$1} = $2; } print Dumper (\%lines);
Of course, this also has an appeal:
my %lines = $info =~ /(\d+): (.+?)$/gm;
Passing a reference to Dumper allows Data::Dumper to dump the entire data structure without listifying it first.
Update: I miscopied the test data. Oops. Negative-width assertions are the way to go. :)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Matching over multiple lines in a scalar
by thpfft (Chaplain) on Oct 27, 2002 at 23:18 UTC | |
by BrowserUk (Patriarch) on Oct 27, 2002 at 23:48 UTC | |
by thpfft (Chaplain) on Oct 28, 2002 at 00:03 UTC | |
Re: Re: Matching over multiple lines in a scalar
by BrowserUk (Patriarch) on Oct 27, 2002 at 22:58 UTC |