RE: Why won't my script terminate?
From: David N Murray (dmurray_at_jsbsystems.com)
Date: Wed, 24 Mar 2004 15:42:42 -0500 (EST) To: LaurieF@benjerry.com
I think knowing which line its hanging up on would be benficial in
diagnosing this. In that regard, why not try the perl debugger. If
you're not familiar with the debugger, here's a quick rundown on the
commands you'll need:
$ perl -d script_name.pl and_any_args_for_script
DB<1> b n*
n* is a line number in your script. the choice of n is pretty arbitrary.
basically, if you get to that line, everything up to that point has
worked. If your editor isn't intelligent enough to give you line numbers,
use the l (lowercase L) command to list the file, with line numbers.
Keep using l to scroll through the file.
(program runs to line n*, or hangs)
If the program doesn't break at the indicated line, you never got there.
Move n* up, and try again. You can try Ctrl-C and then try the T command
(stack trace). YMMV.
will get you a help summary of the debuggers commands.
Regarding Ctrl-D, in a Windows env, its Ctrl-Z and Enter to simulate an
end-of-file condition. In the unix env, its Ctrl-D.
On Mar 24, Laurie Vien scribed:
> >>> Laurie Vien <LaurieF@benjerry.com> 03/24/04 03:18PM >>>
> There are only 3 records in the input table, and they've all been
> to the output file. :-)
> -----Original Message-----
> From: Ronald J Kimball [mailto:firstname.lastname@example.org]
> Sent: Wednesday, March 24, 2004 3:22 PM
> To: 'Hardy Merrill'; LaurieF@benjerry.com; email@example.com
> Subject: RE: Why won't my script terminate?
> She's not re-opening STDOUT as an "in memory" file, she's opening it as
> regular file handle. This doesn't apply.
> I doubt very much that opening STDOUT to a file is the cause of the
> not terminating. I suspect that either there is an infinite loop, or
> there's just a lot of data to process and the original poster isn't
> enough time for the script to finish.
> > -----Original Message-----
> > From: Hardy Merrill [mailto:HMerrill@dhcr.state.ny.us]
> > Sent: Wednesday, March 24, 2004 3:06 PM
> > To: LaurieF@benjerry.com; firstname.lastname@example.org
> > Subject: Re: Why won't my script terminate?
> > I just found this in 'perldoc -f open':
> > Though if you try to re-open "STDOUT" or "STDERR" as an "in
> > memory" file, you have to close it first:
> > close STDOUT;
> > open STDOUT, '>', \$variable or die "Can't open STDOUT: $!";
> > So try closing STDOUT first before opening it for append.
> > HTH.
> > Hardy Merrill
> > >>> Laurie Vien <LaurieF@benjerry.com> 03/24/04 02:44PM >>>
> > I am running a very simple Perl script using DBI (skeleton of it
> > follows).
> > It does everything I expect it to, but the problem is it doesn't
> > finish
> > until I Ctrl-C, at which time I get the message "Terminating on
> > SIGINT(2)". What have I left out or done in the wrong order that
> > causes it
> > not to terminate?:
> > #MyPerlScript.pl
> > use DBI;
> > use Date::Manip;
> > $dbh = DBI->connect($DB_CONN, $DB_USER, $DB_PASS) || die "Can't
> > connect:
> > $dbi::errstr";
> > open(STDOUT, ">>myfile.txt") or die "\nCould not open STDOUT: $!";
> > $sth = $dbh->prepare("SELECT * FROM MyTable");
> > $sth->execute();
> > # < Do bunches of stuff here ....>
> > #
> > #
> > $sth->finish();
> > $dbh->disconnect();
> > close(STDOUT);
> > Laurie