On Wed, Mar 18, 2009 at 1:10 PM, Yossi Itzkovich
<[email protected]> wrote:
> Hi,
> I am looking for a module that will get a file with text lines, and will find 
> repeating patterns.
> Example:  given the following file:
> -----
> I want to go home
> 1+3=4
> Hello World
> 1+3=4
> Hello World
> 8+2=10
> Hello World
> Klskd
> -----
> The script should tell me that the sequence : 1+3=4  and Hello World repeat 2 
> times.  A better script may tell me even that the more general pattern: 
> {number}+number}={number} and Hello World  repeat 3 times.
>
> Any suggestion?
>
> Thanks
> Yossi

Err, I don't understand why do you insist to find a module while
based on your description a simple regex would do.

use File::Slurp;
my $str = read_file("file.txt");

if ($str =~ / ^(  \d+  \+   \d+  = \d+  \n  \w+ )$    \1+ /msx) {
   print $1;
}

you just have to apply it on the whole file at once, hence slurping
the file into a scalar.

Gabor
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl

Reply via email to