Re: How good is PERL at searching ASCII files?



<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


.



Relevant Pages

  • Re: Functions, Arrays and number/text stored as text
    ... May I request you to mail me the workbook at ask@xxxxxxxxxxxxxxxx and explain the problem very clealry. ... Table1 is basically a database holding hundreds of lines. ... everything in Column-A was numbers stored as numbers. ... number (IF/MAX array), etc. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Remove items from GetRows array
    ... > I am pulling data from 3 tables. ... > table1 holds item details ... > I'm looping through the array to find duplicate records in the data I ... > through and pull out a column value to concatenate with the first ...
    (microsoft.public.inetserver.asp.general)
  • Functions, Arrays and number/text stored as text
    ... I have a small array problem. ... Let's call them Table1 and Table2. ... Table1 is basically a database holding hundreds of lines. ... To do this I used mostly VLOOKUPS and ARRAYS. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Functions, Arrays and number/text stored as text
    ... Let's call them Table1 and Table2. ... Table1 is basically a database holding hundreds of lines. ... To do this I used mostly VLOOKUPS and ARRAYS. ... number (IF/MAX array), etc. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Getting Data From / Adding Data To Access DB Table
    ... Let's say I've created a table in an access database called Table1 ... array and an integer array. ... In short: Build a connection to the database, use an OleDbCommand and SQL select command to query the data, use a OleDbDatareader to read the data in a loop and put them into an array - but you should learn it from the start: ...
    (microsoft.public.dotnet.languages.vb)