Re: How good is PERL at searching ASCII files?
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Sat, 09 Dec 2006 06:36:02 GMT
jmartzoo-google@xxxxxxxxx wrote:
The challenge I'm faced with is to search out all occurrences where a
function named CONVERT() is being called with three parameters. It's a
challenge because the function has several signatures and I need to
segregate the three param calls from the two param calls. To make
things even spicier, it's very possible that the parameters may also be
function calls themselves. I think the best strategy becomes finding
the pattern:
CONVERT(<something>,<something>,
The key elements being the string CONVERT, one open paren ( followed by
two commas at the same nesting level.
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')
))
If anybody has a script that I can use to get started
Sure, try this:
#!/usr/bin/perl
use warnings;
use strict;
while ( <> ) {
if ( /convert/i && tr/(// != tr/)// ) {
$_ .= <>;
redo;
}
if ( /convert/i ) {
my $temp = $_;
1 while $temp =~ s/ \( [^()]+ \) (?=.*\)) //sx;
print if $temp =~ tr/,// == 2;
next;
}
print;
}
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- References:
- How good is PERL at searching ASCII files?
- From: jmartzoo-google
- How good is PERL at searching ASCII files?
- Prev by Date: Re: associate + attach?
- Next by Date: Looking for a module
- Previous by thread: Re: How good is PERL at searching ASCII files?
- Next by thread: FAQ 3.6 How do I profile my Perl programs?
- Index(es):