>From Laura wrote:
> 
> Hello,

Hello,

> I am really a beginner not only to perl but to programming!  but here my
> question.
> 
> I have 300 files that I need to go thru.  Each file has an embedded sql
> query.  I want to automatically pull out just the lines that represent the
> query text.  I cannot make grep do this task.  There are several things that
> I know to be true:
> 
> 1.  The beginning of the range always begins with the word "select"
> 2.  The end of the range is always one line above a line that says:
>     "-- end of query"
> 3.  The lines in between this "sandwich" can vary in number and do not have
> good predictable features or rules.
> 
> I know that I will need some programming structure that reads through each
> line of each file and when it finds the occurrence of the word "select" it
> enters into a loop that ends when it finds the string "--end of query."  It
> then takes the chunk and outputs to a file.
> 
> Like I said, I am very new but any pointers would be helpful.  I have been
> told that perl is excellent for such a task and I may be able to get a
> senior programmer here to help me with the loop structure if I can provide
> him with the perl constructs needed.  For instance, should I research the
> array function in Perl?  Any help would be SO SO appreciated!  Thanks!!!


#!/usr/bin/perl -w
use strict;

open OUT, '> sqlquery' or die "Cannot open sqlquery: $!";

while ( <> ) {
    if ( /select/ .. /-- end of query/ ) {
        print OUT unless /-- end of query/;
        }
    }

__END__


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to