in reply to How to create a log file?

Specifically : Any program like addition which does its normal functionality and generates its output like wise for every step in the program I need to verify the statements(I mean the program steps) are executed successfully or not. I knew we could use conditional loops and generate the log file statements to be printed but instead adding it seperately in the program, is there a way to do it automatically through the user defined checkpoints to generate our log file and debug it for the future reference.

Replies are listed 'Best First'.
Re^2: How to create a log file?
by Eliya (Vicar) on Dec 22, 2011 at 16:38 UTC

    Not really sure what you're looking for, but maybe something like the Perl debugger's tracing facility?

    For example, with a silly little program like this

    #!/usr/local/bin/perl sub add { return $_[0] + $_[1]; } sub result { my $sum = shift; $sum = add($sum, shift) while @_; return $sum; } print result(@ARGV);

    running it as follows under the debugger, would produce:

    $ PERLDB_OPTS="NonStop AutoTrace frame=29" perl -d ./silly.pl 2 3 4 Package ./silly.pl. 13: print result(@ARGV); in @=main::result(2, 3, 4) from ./silly.pl:13 8: my $sum = shift; 9: $sum = add($sum, shift) while @_; in $=main::add(2, 3) from ./silly.pl:9 4: return $_[0] + $_[1]; scalar context return from main::add: 5 in $=main::add(5, 4) from ./silly.pl:9 4: return $_[0] + $_[1]; scalar context return from main::add: 9 10: return $sum; list context return from main::result: 0 9 9

    (Note that the technique to set environment variables (PERLDB_OPTS) depends on the shell being used.)

    This shows step by step what is being executed.

    There are also less verbose modes. See perldebug for the meaning of the debugging options like frame etc.