anurag_perl has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: How to create a log file?
by mr.nick (Chaplain) on Dec 22, 2011 at 13:48 UTC
    When I need quick and dirty logging that doesn't affect the output of my script, I do this:

    use strict; use warnings; open STDERR,">","$0.log" or die $!; ... ... warn "this goes to my log file"; ... print "but this doesn't\n"; ....

    mr.nick ...

Re: How to create a log file?
by Marshall (Canon) on Dec 22, 2011 at 12:24 UTC
    Your question is so general that I really don't know how to help you. Can you be more specific? In general you will need to write logging statements in your code - there are a bunch of modules and functions that facilitate that - first of which being: print().
Re: How to create a log file?
by Anonymous Monk on Dec 22, 2011 at 21:28 UTC
Re: How to create a log file?
by anurag_perl (Novice) on Dec 22, 2011 at 13:47 UTC
    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.

      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.

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