Re: How good is PERL at searching ASCII files?
- From: "Bigus" <bigus@xxxxxxxxxxxxxxxx>
- Date: Thu, 7 Dec 2006 17:08:39 -0000
<jmartzoo-google@xxxxxxxxx> wrote in message
news:1165506343.745473.254360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Of the following examples, I would want the first two in my results,
the second two ignored:
yes:
~~~~
1)
CONVERT(varchar(16), @variable, 1)
2)
convert (char(12),
(
SELECT date
FROM table1
WHERE id = @x
AND user IN ('raquel', 'marylin', 'jennifer')
), 7)
no:
~~~~
1)
convert(varchar(16), @variable)
2)
CONVERT (char(12),
(
SELECT date
FROM table2
WHERE id = @y
AND user IN ('huey', 'dewey', 'louie')
))
The following code is a tad sloppy but I'm no Perl expert. Copy it into a
text file and name it something like test.pl. I'll explain it below:
=========CODE===========
use strict;
my $file;
strng();
my @matches = $file =~ /(convert\s*\([^,\n]+,[^,\n]+,[^\)]+\))/gi;
my @matches2 = $file =~
/(convert\s*\([^,\n]+,\s*\n.+?\n.+?\n.+?\n.+?\n.+?\n.*?\)\s*\,[^\)]+\))/gi;
print "@matches\n\n";
print "@matches2";
sub strng {
$file = " yes:
~~~~
1)
CONVERT(varchar(16), \@variable, 1)
2)
convert (char(12),
(
SELECT date
FROM table1
WHERE id = \@x
AND user IN ('raquel', 'marylin', 'jennifer')
), 7)
no:
~~~~
1)
convert(varchar(16), \@variable)
2)
CONVERT (char(12),
(
SELECT date
FROM table2
WHERE id = \@y
AND user IN ('huey', 'dewey', 'louie')
))";
}
========/CODE=======
Basically, your file contents will be in the scalar variable $file (in this
case I've put your examples into $file via the sub strng).
There's 2 regular expressions - the first one matches single line 3 param
convert functions as you illustrate, and places each match into the array
@matches. The second regular expression will match the multi-line convert
functions you illustrate, although the format will have to be quite rigidly
as per your illustration, so if any of your multi-line converts stretch over
more than 7 lines you could get weird results.
You could then merge the 2 arrays, instead of printing then out
indivudually. Anyway, this is just a starting point to get you off the
ground.
Regards
Bigus
.
- References:
- How good is PERL at searching ASCII files?
- From: jmartzoo-google
- How good is PERL at searching ASCII files?
- Prev by Date: Re: Perl storing huge data(300MB) in a scalar
- Next by Date: Re: unix perl cgi notepad question
- Previous by thread: Re: How good is PERL at searching ASCII files?
- Next by thread: Re: How good is PERL at searching ASCII files?
- Index(es):
Relevant Pages
|