package dbS::Sybase::Parse::SQL_File; use warnings; use strict; use Iterator::Simple qw(iterator); BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.0.0; @ISA = qw(Exporter); @EXPORT_OK = qw(&batch); } our $FH; ############################# sub batch { my $file = shift; open ($FH, "<", $file) or die ("unable to open sql file\n"); iterator { my $query = ""; while (my $line = <$FH>) { chomp $line; last if ($line =~ m/^go\s*$/i); $query .= $line . " "; } return $query; } } 1; #### use dbS::Sybase::Parse::SQL_File qw(open_file next_batch); .... if ( my $batch = dbS::Sybase::Parse::SQL_File::batch("SQL/SNAP.sql") ) { print "-"x40 . "\n"; print " Performing IGOR\n"; print "-"x40 . "\n"; while ( my $sql_batch = $batch->next ) { dbh_do($local_dbh, $sql_batch); } }