For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2007 > how to access an array defined in another module









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to access an array defined in another module
vabby

2007-01-06, 7:04 pm

My problem scenario is as follows.
I have a module BatLib1.pm and another module BatLib2.pm and a main
perl module mod_main.pl . Inside BatLib2.pm, there is a function fn1()
, where I declare and define an array like this:
$self->{array_test}[0] = 0;
$self->{array_test}[1] = 1;
$self->{array_test}[2] = 2;

INside mod_main.pl , I create a new instance of Batlib2,
$batlibobj2 = new_Batlib2 Batlib2();

and then a new instance of Batlib1, where I pass as arg the instance of
Batlib2
$batlibobj1 = new_Batlib1 Batlib1($batlibobj2);

Inside Batlib1.pm
I make a call to Batlib2::fn1() and it works so that the array_test
gets populated. Now I have to access this array in Batlib1. How can I
do it:

I tried using $self->{batlibobj2}->{array_test}, but it doesnot work.
Plz note that batlibobj2 is a member variable of Batlib1 which gets
intilaized in the new_Batlib1 function.

Tx
Vabby

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com