http://qs321.pair.com?node_id=635770


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