The code given below is well worked. But the problem is that the variable which is passed from the main program to the package P is only accessible within the sub routine sss. But what i want is that suggest me some technique so that the value of variable which i passes from the main program can be accessible within the module P(i.e it can accessible in any subroutines present inside that module).
#main.pl use strict; use Config::Tiny; use Config::P; my $DATA; open CONFIGFILE2, "imp1.txt" or die $!; { local $/; $/ = undef; $DATA=<CONFIGFILE2>; } print $DATA; # Create a config my $Config = Config::Tiny->new(); # Open the config, replace with read and $DATA with filename $Config = Config::Tiny->read_string( $DATA ); # see perldoc Config::Tiny my $s = $Config->{_}; #passing the variable $s to the module p P::sss($s); #package package p; use strict; my $s1; sub sss { $s1= shift; print $s1->{Local_IP};#it works fine } #out of sub routine it is not accesssible. print $s1->{Local_Port};#it doesn't work 1;
imp1.txt contains
Local_Port=5060
Local_IP = 127.0.0.1

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.