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
In reply to how to pass object to a subroutine by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |