in reply to Re^2: Using an attribute function from a .pm file.
in thread Using an attribute function from a .pm file.
Well I commented out the use strict.What for?
(Though I would like to fix it and use strict. But let us move past this for now.)
No we won't, because the stricture warning gives you a clue about what's happening. You are using something as a hash ref which isn't, at line 42, which reads
open(LOGFILE, ">>$self->{logfile}") or die "Cannot open logfile";
See the hash ref in there, which isn't? You are dying at that line with an unappropriate message. Stick the filename you are trying to open in there, and $! to get the reason why something might go wrong.
Rewriting your sub log_message
sub log_message { my $self=shift; warn "\$self = '$self'\n"; open(LOGFILE, ">>$self->{logfile}") or die "Cannot open logfile '$self->{logfile}': $!"; my $time=getLogTime(); print LOGFILE $time, " "; for (@_){ print LOGFILE @_; } }
I get
$self = 'Entering sub main::do_something ' Can't use string ("Entering sub main::do_something ") as a HASH ref while "strict refs" in use at LogMessages.pm line 43.
You are invoking log_message as a function inside your handler sub created in sub _log
*{ $sym } = sub { log_message("Entering sub $pkg\:\:$name\n"); my @ret = $code->( @_ ); log_message("Leaving sub $pkg\:\:$name\n"); return @ret; };
and perl is just doing what you tell it to do...
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Using an attribute function from a .pm file.
by shobhit (Sexton) on Aug 12, 2007 at 18:26 UTC | |
by shmem (Chancellor) on Aug 12, 2007 at 19:08 UTC | |
by shobhit (Sexton) on Aug 13, 2007 at 09:17 UTC |