[28906] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 150 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 19 03:10:19 2007

Date: Mon, 19 Feb 2007 00:09:04 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 19 Feb 2007     Volume: 11 Number: 150

Today's topics:
        behavior of my print function call <evad.notyals@liamg.moc>
    Re: behavior of my print function call xhoster@gmail.com
    Re: behavior of my print function call <evad.notyals@liamg.moc>
    Re: behavior of my print function call <spamtrap@dot-app.org>
        for jermaine: truly excellent active newsgroups -  egsu <herreiner@asacomp.ca>
        global variables worlman385@yahoo.com
    Re: global variables <kenslaterpa@hotmail.com>
        new CPAN modules on Mon Feb 19 2007 (Randal Schwartz)
    Re: Passing parameters from one Perl script to another  <paduille.4060.mumia.w+nospam@earthlink.net>
    Re: Passing parameters from one Perl script to another  <edMbj@aes-intl.com>
    Re: Perl takes a lot of memory when you just require a  <jain.nsit@gmail.com>
        Why isn't variable maintained between subroutines in .p <itfred@cdw.com>
    Re: Why isn't variable maintained between subroutines i <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 18 Feb 2007 20:34:26 -0700
From: "Dave Slayton" <evad.notyals@liamg.moc>
Subject: behavior of my print function call
Message-Id: <0rKdnRw5F5wkh0TYnZ2dnUVZ_o6gnZ2d@comcast.com>

I have a hash full of filehandles and a scalar variable containing a line of 
text, and try to do this:

print $fh_hash{$key} $line;

which is rejected by the compiler, which says "Scalar found where operator 
expected" near "} $line".  It wants an operator before $line?  I tried 
placing parentheses around $line, but that is likewise rejected on the basis 
of its not being a code reference, so it presumably thinks I'm using the 
parentheses to call a subroutine.  I'm clearly not understanding the parsing 
that's happening there.  Finally, if I surround the file handle with curly 
braces like this:

print {$fh_hash{$key}} $line;

then it works as desired.

Would someone please explain what's going on there?

Thanks! 




------------------------------

Date: 19 Feb 2007 03:39:41 GMT
From: xhoster@gmail.com
Subject: Re: behavior of my print function call
Message-Id: <20070218224100.126$AG@newsreader.com>

"Dave Slayton" <evad.notyals@liamg.moc> wrote:
> I have a hash full of filehandles and a scalar variable containing a line
> of text, and try to do this:
>
> print $fh_hash{$key} $line;
>
> which is rejected by the compiler, which says "Scalar found where
> operator expected" near "} $line".  It wants an operator before $line?

Sure.  For example, the comma operator would make it happy.  perhaps
you wouldn't be happy, but the parser would be.

 ...
>    Finally, if I surround
> the file handle with curly braces like this:
>
> print {$fh_hash{$key}} $line;
>
> then it works as desired.
>
> Would someone please explain what's going on there?

perldoc -f print

I see no reason to think I could do a better job of explaining that
is already done in the documentation.  Have you already read it and
want more explanation?  If so, could you describe in more detail
what you want explained?


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Sun, 18 Feb 2007 21:24:36 -0700
From: "Dave Slayton" <evad.notyals@liamg.moc>
Subject: Re: behavior of my print function call
Message-Id: <mYCdnRBd3trgu0TYnZ2dnUVZ_vamnZ2d@comcast.com>

<xhoster@gmail.com> wrote in message 
news:20070218224100.126$AG@newsreader.com...
> "Dave Slayton" <evad.notyals@liamg.moc> wrote:
>> I have a hash full of filehandles and a scalar variable containing a line
>> of text, and try to do this:
>>
>> print $fh_hash{$key} $line;
>>
>> which is rejected by the compiler, which says "Scalar found where
>> operator expected" near "} $line".  It wants an operator before $line?
>
> Sure.  For example, the comma operator would make it happy.  perhaps
> you wouldn't be happy, but the parser would be.
>
> ...
>>    Finally, if I surround
>> the file handle with curly braces like this:
>>
>> print {$fh_hash{$key}} $line;
>>
>> then it works as desired.
>>
>> Would someone please explain what's going on there?
>
> perldoc -f print
>
> I see no reason to think I could do a better job of explaining that
> is already done in the documentation.  Have you already read it and
> want more explanation?  If so, could you describe in more detail
> what you want explained?

Well, I see that the documentation states the curly braces must be there. 
It doesn't begin to explain why.  Also, some of the other things it offers 
don't seem to work as it suggests, e.g.:
"(NOTE: If FILEHANDLE is a variable and the next token is a term, it may be 
misinterpreted as an operator unless you interpose a "+" or put parentheses 
around the arguments.)"
As I said, parentheses around $file make it think I'm invoking a subroutine, 
and a + right before $file (or $file surrounded by parentheses) gives me a 
very large number for output.  Putting in a comma as you said does indeed 
make the parser happy, but doesn't produce the desired result (which is why 
I wouldn't be happy, I guess).

>
>
> Xho
>
> -- 
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service                        $9.95/Month 30GB 




------------------------------

Date: Sun, 18 Feb 2007 23:26:08 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: behavior of my print function call
Message-Id: <m2d546wz6n.fsf@local.wv-www.com>

"Dave Slayton" <evad.notyals@liamg.moc> writes:

> Finally, if I surround the file handle with curly 
> braces like this:
>
> print {$fh_hash{$key}} $line;
>
> then it works as desired.
>
> Would someone please explain what's going on there?

Why? Is there something wrong with the explanation in "perldoc -f print"?

    Note that if you're storing FILEHANDLES in an array or other
    expression, you will have to use a block returning its value
    instead:

        print { $files[$i] } "stuff\n";
        print { $OK ? STDOUT : STDERR } "stuff\n";

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: 19 Feb 2007 05:03:18 GMT
From: byrom <herreiner@asacomp.ca>
Subject: for jermaine: truly excellent active newsgroups -  egsu awge - (1/1)
Message-Id: <885q7t8996342r8t98557A64584e8674548p97444644B652395643E@news.asacomp.ca>

Hey

With some of the fastest connections around it's no wonder people love it and keep coming back.
Take a look at all the great features below and imagine! You'll LOVE it.
One thing I love about them, they don't keep log files of the news I read or files I download.

2,000,000 new posts each day
Blazing fast downloads
800 GIGS of new multimedia content each day
Keyword searchable

I hope everyone comes to see what I'm talking about: http://newsdude.net


I eptenervec ...


------------------------------

Date: Sun, 18 Feb 2007 16:35:41 -0800
From: worlman385@yahoo.com
Subject: global variables
Message-Id: <m6sht2t3nfhmp8oa04h5576g5eduvih05v@4ax.com>

if I call a perl function 26 times,

are the variables  $decode, $flag global variables?

I thought they are local variables like methods in Java, once the
function returns, $decode , $flag will get destroy.

But when i look into komodo debugger they are global variables.

How can i use them as local variables like method variables in Java?

Thanks



for ( $i = 1; $i <= 26; $i++)
{
    decode($i);   
}

sub decode
{
    $decode = "";	
    $flag = $_[0];
    if ( $flag != undef ) {
        $data_file="brute.txt";
    } else {
        $data_file="encoded.txt";
        $flag = 3;
    }
    open(DAT, $data_file) || die("Could not open encoded.txt!");
    @raw=<DAT>;
    close(DAT);  
}


------------------------------

Date: 18 Feb 2007 16:58:06 -0800
From: "kens" <kenslaterpa@hotmail.com>
Subject: Re: global variables
Message-Id: <1171846685.966171.171430@v45g2000cwv.googlegroups.com>

On Feb 18, 7:35 pm, worlman...@yahoo.com wrote:
> if I call a perl function 26 times,
>
> are the variables  $decode, $flag global variables?
>
> I thought they are local variables like methods in Java, once the
> function returns, $decode , $flag will get destroy.
>
> But when i look into komodo debugger they are global variables.
>
> How can i use them as local variables like method variables in Java?
>
> Thanks
>
> for ( $i = 1; $i <= 26; $i++)
> {
>     decode($i);
>
> }
>
> sub decode
> {
>     $decode = "";
>     $flag = $_[0];
>     if ( $flag != undef ) {
>         $data_file="brute.txt";
>     } else {
>         $data_file="encoded.txt";
>         $flag = 3;
>     }
>     open(DAT, $data_file) || die("Could not open encoded.txt!");
>     @raw=<DAT>;
>     close(DAT);
>
> }

No, they are not 'local' variables. They are global to the package
they are used in.

Use a lexical variable (declared with the 'my' keyword to limit a
variable's scope.

For instance:

sub decode
{
    # This variables are only scoped for subroutine
    # decode.
    my $decode = "";
    my $flag = $_[0];
    ...

Note that you should always start your programs with the following two
lines:

use strict;
use warnings;

Using strict will force you to define all variables, thus, they will
not default to be a package global.  It will alos save you from
misspelling variable names (at least part of the time - you could
misspell it to the name of another variable I suppose).

HTH, Ken




------------------------------

Date: Mon, 19 Feb 2007 05:42:10 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Feb 19 2007
Message-Id: <JDp3uA.1C8@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Acme-Kensiro-0.01
http://search.cpan.org/~tokuhirom/Acme-Kensiro-0.01/
kensiro-sinsu
----
CPAN-1.88_75
http://search.cpan.org/~andk/CPAN-1.88_75/
query, download and build perl modules from CPAN sites
----
CPAN-SQLite-0.1
http://search.cpan.org/~rkobes/CPAN-SQLite-0.1/
maintain and search a minimal CPAN database
----
CPANPLUS-0.77_03
http://search.cpan.org/~kane/CPANPLUS-0.77_03/
API & CLI access to the CPAN mirrors
----
DateTime-TimeZone-0.61
http://search.cpan.org/~drolsky/DateTime-TimeZone-0.61/
Time zone object base class and factory
----
DateTime-TimeZone-0.6101
http://search.cpan.org/~drolsky/DateTime-TimeZone-0.6101/
Time zone object base class and factory
----
Egg-Release-1.01
http://search.cpan.org/~lushe/Egg-Release-1.01/
WEB application framework release version.
----
File-Find-Parallel-v0.0.2
http://search.cpan.org/~andya/File-Find-Parallel-v0.0.2/
Traverse a number of similar directories in parallel
----
Finance-QuoteTW-0.04
http://search.cpan.org/~alec/Finance-QuoteTW-0.04/
Fetch quotes of mutual funds in Taiwan
----
GD-Graph-Polar-0.11
http://search.cpan.org/~mrdvt/GD-Graph-Polar-0.11/
Make polar graph using GD package
----
HTML-Copy-1.111
http://search.cpan.org/~tkurita/HTML-Copy-1.111/
copy a HTML file without breaking links.
----
HTTP-Async-0.07
http://search.cpan.org/~evdb/HTTP-Async-0.07/
process multiple HTTP requests in parallel without blocking.
----
HTTunnel-Client-0.06
http://search.cpan.org/~patl/HTTunnel-Client-0.06/
Client class for Apache::HTTunnel
----
IO-Tty-Util-0.03
http://search.cpan.org/~patl/IO-Tty-Util-0.03/
Perl bindings for libutil.so tty utility functions
----
Image-Pngslimmer-0.12
http://search.cpan.org/~acmcmen/Image-Pngslimmer-0.12/
slims (dynamically created) PNGs
----
LaTeX-TOM-0.5_05
http://search.cpan.org/~schubiger/LaTeX-TOM-0.5_05/
A module for parsing, analyzing, and manipulating LaTeX documents.
----
MSDOS-Attrib-1.02
http://search.cpan.org/~cjm/MSDOS-Attrib-1.02/
Get or set MS-DOS file attributes
----
Net-Amazon-0.39
http://search.cpan.org/~boumenot/Net-Amazon-0.39/
Framework for accessing amazon.com via REST
----
Net-OICQ-1.3002
http://search.cpan.org/~tangent/Net-OICQ-1.3002/
Perl extension for QQ instant messaging protocol
----
Object-InsideOut-3.11
http://search.cpan.org/~jdhedden/Object-InsideOut-3.11/
Comprehensive inside-out object support module
----
PerlMagick-6.32
http://search.cpan.org/~jcristy/PerlMagick-6.32/
----
Regexp-Compare-0.06
http://search.cpan.org/~vbar/Regexp-Compare-0.06/
partial ordering for regular expressions
----
SOAP-XML-Client-2.0
http://search.cpan.org/~llap/SOAP-XML-Client-2.0/
Simple frame work for talking with web services
----
WWW-Mechanize-GZip-0.10
http://search.cpan.org/~pegi/WWW-Mechanize-GZip-0.10/
tries to fetch webpages with gzip-compression
----
WWW-Monitor-0.11
http://search.cpan.org/~yaron/WWW-Monitor-0.11/
Monitor websites for updates and changes
----
namespace-clean-0.01
http://search.cpan.org/~phaylon/namespace-clean-0.01/
Keep imports out of your namespace
----
re-engine-Plugin-0.01
http://search.cpan.org/~avar/re-engine-Plugin-0.01/
Pure-Perl regular expression engine plugin interface


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Mon, 19 Feb 2007 06:20:01 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: Passing parameters from one Perl script to another 
Message-Id: <lkbCh.3849$tD2.1399@newsread1.news.pas.earthlink.net>

On 02/18/2007 12:08 PM, Ed Jay wrote:
> Jürgen Exner scribed:
> 
>> Ed Jay wrote:
>>> I apologize in advance for asking what probably has a simple answer
>>> that I can't seem to find.
>>>
>>> Can I pass parameters from one Perl script to another Perl script
>> Trivial. When script A calls script B just pass the parameters along just as 
>> you would do when calling any other program. 
> 
> I knew it had to be trivial, but to a Perl newbie, nothing is really
> trivial. :-)
> 
>> And script B will find the 
>> parameter in @_, just as if called from the command line.
>> If you want to pass more complex data than simple parameters Perl also 
>> supports pretty much any commonly used IPC method.
>>
> I understand there are several IPC methods available. Again, as a newbie
> trying to solve some script problems without a comprehensive Perl
> understanding, I simply am at a loss at how to do it.
> 
> I'm trying to use the redirect function to port one scripts parameters to

port?

> another script that generates a dynamic HTML page. I don't want to use
> cookies or files. I'm currently snowed at how to do it.
> 
> Thanks for your input.

If you meant that you want to post one script's parameters to another 
script, you can use either a status 307 "Temporary Redirect":

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8

or LibWWW-Perl: http://search.cpan.org/~gaas/libwww-perl-5.805/lwpcook.pod
http://search.cpan.org/dist/libwww-perl/lib/LWP/UserAgent.pm


-- 
Windows Vista and your freedom in conflict:
http://www.regdeveloper.co.uk/2006/10/29/microsoft_vista_eula_analysis/


------------------------------

Date: Mon, 19 Feb 2007 00:04:30 -0800
From: Ed Jay <edMbj@aes-intl.com>
Subject: Re: Passing parameters from one Perl script to another 
Message-Id: <7emit2hqns9h1g5edbg3s9519tatfgp46a@4ax.com>

Mumia W. scribed:

>On 02/18/2007 12:08 PM, Ed Jay wrote:
>> Jürgen Exner scribed:
>> 
>>> Ed Jay wrote:
>>>> I apologize in advance for asking what probably has a simple answer
>>>> that I can't seem to find.
>>>>
>>>> Can I pass parameters from one Perl script to another Perl script
>>> Trivial. When script A calls script B just pass the parameters along just as 
>>> you would do when calling any other program. 
>> 
>> I knew it had to be trivial, but to a Perl newbie, nothing is really
>> trivial. :-)
>> 
>>> And script B will find the 
>>> parameter in @_, just as if called from the command line.
>>> If you want to pass more complex data than simple parameters Perl also 
>>> supports pretty much any commonly used IPC method.
>>>
>> I understand there are several IPC methods available. Again, as a newbie
>> trying to solve some script problems without a comprehensive Perl
>> understanding, I simply am at a loss at how to do it.
>> 
>> I'm trying to use the redirect function to port one scripts parameters to
>
>port?

Old guy talk. :-)
>
>> another script that generates a dynamic HTML page. I don't want to use
>> cookies or files. I'm currently snowed at how to do it.
>> 
>> Thanks for your input.
>
>If you meant that you want to post one script's parameters to another 
>script, 

Exactly.

>you can use either a status 307 "Temporary Redirect":
>
>http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8
>
>or LibWWW-Perl: http://search.cpan.org/~gaas/libwww-perl-5.805/lwpcook.pod
This is the key I needed..

>http://search.cpan.org/dist/libwww-perl/lib/LWP/UserAgent.pm

Thanks for the resources. 
-- 
Ed Jay (remove 'M' to respond by email)


------------------------------

Date: 18 Feb 2007 22:24:24 -0800
From: "RJ" <jain.nsit@gmail.com>
Subject: Re: Perl takes a lot of memory when you just require a file
Message-Id: <1171866264.111412.138310@s48g2000cws.googlegroups.com>

On Feb 18, 6:34 pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2007-02-18 09:12, RJ <jain.n...@gmail.com> wrote:
>
> > On Feb 16, 4:38 pm, anno4...@radom.zrz.tu-berlin.de wrote:
> >> RJ <jain.n...@gmail.com> wrote in comp.lang.perl.misc:
> >> > First of all, if I just do a `require"<generated_file.pl>" ` it takes
> >> > a lot of memory (around 4Mb for 2 Mb file even if I do just a return
> >> > after entering pass_data_from_perl_to_c and populate no Data).
> >> > If I do populate data in form of 3-D array is perl memory requirement
> >> > is 5 times than expected.
>
> >> Perl often takes more memory than expected.  Adjust your expectations.
>
> > My main concern here is that even if return from very beggining of
> > function pass_data_from_perl_to_c , even then perl takes a lot of
> > memory in just requiring file '<generated_file.pl>' while I am
> > populating no data structures.
>
> I don't understand what you expect to happen when you "justrequire" the
> file. When yourequirea file, it is compiled and the compiled code is
> stored in memory. Any data embedded in the code is of course compiled
> (converted to perl data structures) and stored, too.
>
I just want to clarify one thing over here. There are only function
calls in these generated
perl file. It looks something like follows -

<Prototype>
<spyDecompileTagData(index,rName,{"t1" => "1","t2" =>
["100","200"],"t3" => "200"});>

<Example snippet>
======================================================================================
spyDecompileTagData(537,"",{"INCR" => "1","tag1" =>
["100","200"],"tag0" => "200"});
spyDecompileTagData(538,"",{"INCR" => "1","tag2" =>
"tag2.value2","tag3" => "default"});
spyDecompileTagData(539,"",{"INCR" => "1","tag4" =>
["tag4.value1","tag4.value3"]});
spyDecompileTagData(540,"",{"INCR" => "1","tag1" => ["200"]});
spyDecompileTagData(541,"",{"INCR" => "1","tag1" => ["200"]});
spyDecompileTagData(542,"",{"INCR" => "1","tag4" => ["default"]});
spyDecompileTagData(543,"",{"INCR" => "1","tag4" => ["tag4.value3"]});
spyDecompileTagData(544,"",{"INCR" => "1"});
spyDecompileTagData(545,"",{"INCR" => "1","tag1" => ["200"]});
spyDecompileTagData(546,"",{"INCR" => "1"});
spyDecompileTagData(547,"",{"INCR" => "1","tag1" => ["200"]});
spyDecompileTagData(548,"",{"INCR" => "1"});
spyDecompileTagData(549,"",{"INCR" => "1"});
spyDecompileTagData(550,"",{"INCR" => "1","tag4" => ["tag4.value1"]});
spyDecompileTagData(551,"",{"INCR" => "1","STATUS" => "FIXED"});
spyDecompileTagData(552,"",{"INCR" => "1","STATUS" => "TOFIX"});
spyDecompileTagData(553,"",{"INCR" => "1","STATUS" => "ANALYZE"});
spyDecompileTagData(554,"",{"INCR" => "1","tag9" => "1","tag8" =>
"3.14","tag7" => "a"});
spyDecompileTagData(555,"",{"INCR" => "1","tag11" => "2","tag12" =>
"1","tag9" => "2","tag8" => "9.8","tag0" => "0","tag7" => "c"});
======================================================================================
There is no other things in this perl file other than these function
calls.
Now if I just make a return from inside 'spyDecompileTagData' after
doing 3 shift stmts (one for each argument passed to this function),
still perl takes a lot of memory. I have used above format just to
avoid parsing as I you can see the values passed in 3rd argument can
be quite complex (a hash whose values can be scalar/array refrence or
even a hash refrence. I don't want perl to store
the whole file in code section but I want to compile code inline. Is
there anyway to do so.

> > Is there anyway to avoid that (or some way to execute the function
> > calls in ,'<generated_file.pl>' infile without loading file in
> > memory), since there can be case , when I have to 'require'
> > this file but I would need not populate single information from here.
>
> Separate the data from the code. Perl is good for reading and writing
> files - use it!
>
>         hp
>
> --
>    _  | Peter J. Holzer    | Es ist ganz einfach ihn zu verstehen, wenn
> |_|_) | Sysadmin WSR       | man nur alle wichtigen Worte im Satz durch
> | |   | h...@hjp.at         | andere ersetzt.
> __/   |http://www.hjp.at/|      -- Nils Ketelsen in danr




------------------------------

Date: Sun, 18 Feb 2007 14:09:39 -0500
From: Fred <itfred@cdw.com>
Subject: Why isn't variable maintained between subroutines in .pm module?
Message-Id: <bqWdnZK4IPXuOUXYnZ2dnUVZ_hisnZ2d@comcast.com>

According to the docs, if you define a variable using the 
"use vars" pragma in a perl module, then that variable should 
be available across the entire .pm module.  Listed below I have
an excerpt from a module named test.pm.  The $host variable is
defined with the "usr vars" pragma, but I can't access it from
the subroutine test() below.

Essentially what I want to do is use AppConfig to read values
from a configuration file like host, port, etc., then have
them available to other subroutines when called.  I'm trying
to avoid having to read the config file every time a subroutine
is called.  Is this possible without using the Storable module?

-Thanks



our @EXPORT = qw(
  LoadConfig
);

our $VERSION = '0.01';

use vars qw($host $VERSION @ISA @EXPORT @EXPORT_OK);


sub LoadConfig
{
  shift @_;
  my ($cfgfile) = @_;

  our $config = AppConfig->new(
    {
     CASE   => 1,
     PEDANTIC => 0,
     CREATE => 1,
     ERROR => sub {},
     GLOBAL => { ARGCOUNT => ARGCOUNT_ONE }
    }
  ); 

  $config->file($cfgfile);


  my $host = $config->host();

  #####The $host variable is assigned here
  print "HOST IN LoadConfig: $host\n";

} 



sub test
{

  ######I can't reference $host in different subroutine
  print "IN TEST() HOST IS: $host\n";

} 



------------------------------

Date: Sun, 18 Feb 2007 20:34:04 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Why isn't variable maintained between subroutines in .pm module?
Message-Id: <53ro4mF1tv88mU1@mid.individual.net>

Fred wrote:
> 
> use vars qw($host $VERSION @ISA @EXPORT @EXPORT_OK);
> 
> sub LoadConfig

<snip>

>   my $host = $config->host();
> 
>   #####The $host variable is assigned here

Yes, but that's the lexical variable $host, which is not the same as the 
package global $host you declared via the "use vars" statement.

Try without "my".

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 150
**************************************


home help back first fref pref prev next nref lref last post