in reply to Re^2: ALTER SPROC activation
in thread ALTER SPROC activation

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^4: ALTER SPROC activation
by ikegami (Patriarch) on Sep 19, 2005 at 17:20 UTC

    Close.
    last OUTER;
    should be
    last OUTER unless $line = <$FH>;
    You only want to do it when the end of the file is reached.

    Update: Fixed these problems: $FH indicated a file handle but contained a filename, $FH was used as a file handle even though FILE was the file handle, $batch was not initialized, and $line was uselessly checked for "go" twice.

    foreach my $filename (@files) { open(my $fh, '<', $filename) or die("Unable to open input file $filename: $!\n"); my $batch = ''; OUTER: while (my $line = <$fh>) { while (not $line =~ m/^\s*go\s*$/i) { $batch .= $line; last OUTER unless $line = <$fh>; } $dbh->do($batch); } }

    or without nested loops:

    foreach my $filename (@files) { open(my $fh, '<', $filename) or die("Unable to open input file $filename: $!\n"); my $batch = ''; while (my $line = <$fh>) { if (not $line =~ m/^\s*go\s*$/i) { $batch .= $line; next; # Go read next line. } $dbh->do($batch); $batch = ''; } }
    A reply falls below the community's threshold of quality. You may see it by logging in.