Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to read batches of SQL from a file in Perl

by mpeppler (Vicar)
on Aug 29, 2007 at 11:25 UTC ( #635770=note: print w/replies, xml ) Need Help??


in reply to How to read batches of SQL from a file in Perl

You can also make the iterator a little simpler by changing the record separator:
local $/="\ngo\n"; while(<IN>) { chomp; # now the entire statement is in $_... ... execute the SQL statement, with error checking, etc. }
The disadvantage is that $/ can't be a regex, so you can't handle upper/lower case, for example.

Michael

Replies are listed 'Best First'.
Re^2: How to read batches of SQL from a file in Perl
by KurtSchwind (Chaplain) on Oct 25, 2007 at 02:05 UTC
    Wouldn't it be nicer and more flexible to allow people to specify the seperator? I like the idea of essentially slurping the files in and specifying the break as a NEWLINEgoNEWLINE as you did, but I think that a semi-colon is more common.

    I realize that the stated assumption was that the statements end with a 'go', but it would be such a minor change to make it so much more flexible.

      A similar module is SQL::Script, which seems like a good idea (and it has the separator :)

      The default for Sybase isql scripts is to end with "go", so it makes sense to do it this way.

      Other separators can of course be used - it all depends on what your purpose is.

      Michael

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://635770]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2020-12-01 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (6 votes). Check out past polls.

    Notices?