in reply to Matching over multiple lines in a scalar
For more info on $\ look at perlvar{ local $/ = undef; $info = <DATA>; }
Apart from this, I have changed the regex a little bit to do more of what I think you want it to do. Here is the code.
and here is the output:use strict; use warnings; use Data::Dumper; my $info; { local $/ = undef; $info = <DATA>; } my %lines; while ($info =~ m/(\d+)\: (.+?)\n(?=\d)/gs) { $lines{$1} = $2; } print Dumper (%lines); __DATA__ 3: Tag <test> found Tag <test> found 5: Tag <test> found 7: Tag <test> found 14: Tag <test> found 16: Tag <test> found 18: Tag <test> found 21: Tag <test> found 25: Tag <test> found 27: Tag <test> found 29: Tag <test> found 32: Tag <test> found 34: Tag <test> found 49: Tag <test> found 80: Tag <test> found 98: Tag <test> found Tag <test> found
. The regex: m/(\d+)\: (.+?)\n(?=\d)/gs$VAR1 = '29'; $VAR2 = 'Tag <test> found'; $VAR3 = '21'; $VAR4 = 'Tag <test> found'; $VAR5 = '7'; $VAR6 = 'Tag <test> found'; $VAR7 = '14'; $VAR8 = 'Tag <test> found'; $VAR9 = '80'; $VAR10 = 'Tag <test> found'; $VAR11 = '32'; $VAR12 = 'Tag <test> found'; $VAR13 = '16'; $VAR14 = 'Tag <test> found'; $VAR15 = '49'; $VAR16 = 'Tag <test> found'; $VAR17 = '25'; $VAR18 = 'Tag <test> found'; $VAR19 = '3'; $VAR20 = 'Tag <test> found Tag <test> found'; $VAR21 = '34'; $VAR22 = 'Tag <test> found'; $VAR23 = '18'; $VAR24 = 'Tag <test> found'; $VAR25 = '27'; $VAR26 = 'Tag <test> found'; $VAR27 = '5'; $VAR28 = 'Tag <test> found';
Well, I think this is what you want.
UPDATE: I meant to have placed the Dumper(\%lines) as BrowserUK has done below, instead of just Dumper(%lines). Don't know what I was thinking.
-enlil
|
---|
Replies are listed 'Best First'. | |
---|---|
(jeffa) 2Re: Matching over multiple lines in a scalar
by jeffa (Bishop) on Oct 27, 2002 at 23:54 UTC | |
Re: Re: Matching over multiple lines in a scalar
by Rich36 (Chaplain) on Oct 27, 2002 at 22:33 UTC | |
Re: Re: Matching over multiple lines in a scalar
by Louis_Wu (Chaplain) on Oct 27, 2002 at 23:32 UTC |