[Israel.pm] patterns findings

Yossi Itzkovich Yossi.Itzkovich at ecitele.com
Wed Mar 18 07:26:03 PDT 2009

The problem is that I don't know the patterns - I want the script to find.
Let me explain the need:
We have a big tracing log of SQL queries to DB. We want to analyze it and find if there are repeating sequences of same  queries, and optimize them (make one big query, or change application code). 


-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Gabor Szabo
Sent: Wednesday, March 18, 2009 2:29 PM
To: Perl in Israel
Subject: Re: [Israel.pm] patterns findings

On Wed, Mar 18, 2009 at 1:10 PM, Yossi Itzkovich
<Yossi.Itzkovich at ecitele.com> 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.

Perl mailing list
Perl at perl.org.il

More information about the Perl mailing list