#! perl -w use strict; use warnings; use DBI; use DBD::ODBC; use File::Copy; my ($data_source, $database, $user_id, $password) = qw(127.0.0.1 not_telling not_telling not_telling ); # This ip address is an address that is common to all computers and therefore is a perminant ip address my $conn_string = "driver={SQL Server}; Server=$data_source; Database=$database; Trusted_Connection=yes"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::errstr; my @files; my $line; my $file; while (<*.sql>) { next if $_ eq 'Activate.sql'; $file = $_; open (FILE, "$file"); my $line_number = 0; my $run; LINE: while (){ my $line = $_; $line_number = $line_number +1; $run = 1; if ($line_number == 1){ $run = 0 if $line !~ m/^ALTER\sPROCEDURE\s/; last LINE; } else { $run = 1; } last LINE; } if ($run == 1){ push (@files, $file); } else { #Do nothing } } print "@files"; my $line_B; my $FH; my $batch; foreach my $filename ( @files ) { open ( FILE, "<", $filename ) or die( "Couldn't open $filename: $!" ); my $batch = ""; INNER: while (()) { # s/ALTER\bPROCEDURE/CREATE PROCEDURE/; $batch .= $_; last INNER if eof || m/^\s*go\s*$/i; } # print $batch; # sleep 5; $dbh->do($batch) if ($batch =~ m/\s*go\s*$/msi); #http://perldoc.perl.org/perlre.html }