Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi, i am using perl from 1 year. But i am new to OOPS. I have a class used to write the log messages to the file
use Test_logger; my $log = Test_logger -> new();
There is a constructor which will create a unique log file. Ex : Feb_14_2008_15_30_30 ( Month_Day_Year_Hour_Min_Sec). I have a method called message to receive a scalar value and write the contents of scalar to the log file.
$log -> message (" Start of program");
This works fine. But i have a lot of my own modules in my main program. So when i call these subroutines i want to pass this log object to the subroutine so that the subroutine logs also can be visible. Hence i want to pass this object to the subroutine and write logs there. But This is not working.
Ex:
use ADDITION ( &test_addition); test_addition ( $log); sub test_addition { my $log = shift; $log -> message ("Inside the subroutine test_addition); } In my main program print $log ; gives HASH(0x1e2ec5c) in the subroutine print $log ; gives HASH(0x1e2ec5c)
20080215 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to pass object to a subroutine
by moritz (Cardinal) on Feb 14, 2008 at 10:29 UTC | |
|
Re: how to pass object to a subroutine
by johngg (Canon) on Feb 14, 2008 at 12:05 UTC | |
|
Re: how to pass object to a subroutine
by almut (Canon) on Feb 14, 2008 at 12:48 UTC | |
|
Re: how to pass object to a subroutine
by cdarke (Prior) on Feb 14, 2008 at 12:45 UTC |