in reply to Best way to fix a broken but functional program?

what fun!

Here are my suggestions...

Add a log function:

sub log { open (LOG,">>log") || die $!; print LOG "$_[0]\n"; close LOG; }
Then, at the beginning and end of each sub-routine, add:
sub sub-name { log("Entering sub-name"); ... log("Leaving sub-name"); }
Then add various log calls when things happen that you're unsure of, tacking vars used. eg:
log("querying VAX: $vaxen_query"); execute $vaxen_query; log("SQL query: $mangled_sql_query"); execute $mangled_sql_query;
Adding some vars fom caller() may also give you some added insight.

Once you have some idea what gets sent where and when, you can replan what the scipt does and rewite cleanly.

HTH

cLive ;-)

Replies are listed 'Best First'.
Re (tilly) 2: Best way to fix a broken but functional program?
by tilly (Archbishop) on Aug 23, 2001 at 16:00 UTC
    If you want to write such a logging function, there is no need to add it manually everywhere. Try just dropping the following at the start of the script:
    foreach my $used (keys %main::) { no strict; if (defined &$used) { my $old_sub = \&$used; *$used = sub { print "Calling $used\n"; &$old_sub; }; } }
    This one only abuses subroutines in your main package. Alter as desired. :-)