Hi
I using system command 'echo' here. I didn't use open and print since I have to log multiple times at different functions I have. So, I will have to open, write my log and close it again multiple times. Is it advisable?
I thought echo would fulfill the same purpose..!!
Correct me if i am wrong.
| [reply] |
| [reply] |
| [reply] |
sajanagr:
No, don't use the echo command from the shell. It's nearly always a bad idea. Just go ahead and do it with a logger package or with print statements.
Anyway, I'd suggest that you go ahead and write your script to just print your logging information to the standard output. Then you can redirect the output to a file after you have it debugged. You can redirect it either by:
- Redirect STDOUT at the beginning of your perl program, so the print statements will all point to the file, like so:
#!/usr/bin/perl
use strict;
use warnings;
print "before IO redirection\n";
close STDOUT;
open STDOUT, ">", "/log/foo" or die $!;
print "after IO redirection\n";
- Execute the command from a shell, and tell the shell to do the redirection for you. You can do this even if you schedule the job with cron, Task Manager, etc. Just schedule a wrapper script like this:
perl the_script.pl >/log/foo
...roboticus
| [reply] [d/l] [select] |