> I have a file that contains, among
> other things, SQL that is
> bracketed by BEGINSQL and ENDSQL.
> 
> I have written perl code that parses
> this out and executes it, and it is
> working for 99% of the cases.
> 
> I am getting some SQL though that
> spans multiple lines.
> 
> How can I parse out this case?

A simple hack:

local $/ = "ENDSQL";

# And the demonstration
while (<DATA>) {
    tr/\n/ /; # Turn newlines into spaces
    print $..':'.' '.$_; # Neat eh?  Anyway, it just
        #prints each SQL query with line numbering
    print "\n" x 3;
}

__DATA__
BEGINSQL SELECT *
FROM BLAH
WHERE FOO = BAR
ENDSQL

BEGINSQL
SELECT NAME
FROM
TELEPHONEBOOK
WHERE
SURNAME = 'PATON'
ENDSQL

__END__

However, although you are 99% there, you
might wanted to use Parse::RecDescent.  It
does most of the hard work, making your
life simpler - bet you wish you had been
told before you started?  ;)

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

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

Reply via email to