it should work, right?
In addition to the comments by the others, I would suggest using flock, turning on Data::Dumper's Useqq option, and adding more error checking.
use warnings; use strict; use Fcntl qw/:flock/; use Data::Dumper; sub write_log { my ($file, $obj) = @_; open my $fh, '>>', $file or die "open $file: $!"; flock($fh, LOCK_EX) or die "flock $file: $!"; print {$fh} Data::Dumper->new([$obj])->Useqq(1)->Dump or die "print $file: $!"; close $fh or die "close $file: $!"; } write_log("/tmp/log.txt", {hello=>"world"});
If that didn't work or die, personally I would assume the code really wasn't being run, or perhaps that some other process was messing with the logfile. (Note it's been a while since I've used flock on Windows, but I assume you're on *NIX based on your filename.)
There's definitely nothing wrong with the logfile
Well now that you've said that, I have to ask ;-) Are you sure? SELinux? Are all the processes spawned by the script running as the same user?
In reply to Re: Why can't some of my modules do log output to a file?
by haukex
in thread Why can't some of my modules do log output to a file?
by LittleJack
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |