in reply to How can i pass a variable from a program to a module so that it is accessible to the entire module.???

Well ... the code above is a bit messy (mixing OO methods with module subroutines, package P vs Config::P). To answer the question, you need to export the symbol $s1.

-derby

Scratch that ... I didn't see *inside* the module. It is visibile inside the module ... but your not coding it correctly.

Using just OO and not package subs, here's one way to do it:

use strict; use warnings; use Config::Tiny; use MyConfig::P; my $DATA; open CONFIGFILE2, "imp1.txt" or die $!; { local $/; $/ = undef; $DATA=<CONFIGFILE2>; } close CONFIGFILE2; my $Config = Config::Tiny->new(); $Config = Config::Tiny->read_string( $DATA ); my $s = $Config->{_}; my $p = MyConfig::P->new( $s ); $p->sss(); $p->ppp();
package MyConfig::P; sub new { my( $class, $val ) = @_; my $self = {}; $self->{config} = $val; bless $self, $class; } sub sss { my $self = shift; print $self->{config}{Local_IP}, "\n"; } sub ppp { my $self = shift; print $self->{config}{Local_Port}, "\n"; } 1;
  • Comment on Re: How can i pass a variable from a program to a module so that it is accessible to the entire module.???
  • Select or Download Code