Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

dbg - put any script in debug mode

by Maestro_007 (Hermit)
on Sep 27, 2001 at 21:28 UTC ( #115173=snippet: print w/replies, xml ) Need Help??
Description: Put a script in debug mode in a hurry!

Just type 'dbg' to put it in debug mode! It adds '-d' to the shebang line. It's sister, 'udbg' is nearly the same thing (takes the '-d' away).

Probably could use some golfing, but it's always worked for me...

here's 'dbg'

open INFILE, "$ARGV[0]";
@file = <INFILE>;
close INFILE;
$_ = shift @file;
/^#!/ or die "no shebang, file left untouched";
/-d/ and die "file already in debug mode";
s/$/ -d/;
open OUTFILE, ">@ARGV[0]";
print OUTFILE $_;
for (@file) { print OUTFILE $_ }
close OUTFILE;

and it's sister, 'udbg'

open INFILE, "$ARGV[0]";
@file = <INFILE>;
close INFILE;
$_ = shift @file;
/-d/ ? s/-d// : die "file not in debug mode, untouched";
open OUTFILE, ">@ARGV[0]";
print OUTFILE $_;
for (@file) { print OUTFILE $_ }
close OUTFILE;
Replies are listed 'Best First'.
Re: dbg - put any script in debug mode
by merlyn (Sage) on Sep 27, 2001 at 22:00 UTC
      This is something I use for scripts that are called by other scripts. If there's a wrapper script that manages flow, for example, it's easier to put the target script in debug mode than to find out where it's being called and put the parameter there. With that in mind, it's much easier.


        Based on painful experience I submit that a complex system of scripts that call other scripts is itself a serious problem. Instead I suggest moving functionality into modules, and making individual scripts wrappers around the appropriate module. Then your wrapper script can be built quite directly by loading a bunch of modules and making the right calls.

        This makes consistent error handling tremendously easier, and with a single confess you can figure out exactly who called what where whenever you want.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://115173]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2023-01-29 19:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found