Re: sub local variable changes global variable.

2011-10-17 Thread Rob Dixon
On 16/10/2011 00:08, JPH wrote: I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub local is

Re: sub local variable changes global variable.

2011-10-16 Thread Rob Dixon
On 16/10/2011 23:18, Rob Dixon wrote: On 16/10/2011 19:10, JPH wrote: Every pass I only change a single character, then I run some tests and so on. I wonder if it is possible to write your subroutine by using a single global array and remembering the change so that you can undo it before the

Re: sub local variable changes global variable.

2011-10-16 Thread Rob Dixon
On 16/10/2011 19:10, JPH wrote: On 10/16/2011 04:05 AM, Shawn H Corey wrote: On 11-10-15 07:44 PM, Rob Dixon wrote: sub try { my @b; foreach my $row (@_) { push @b, [@$row]; } : } Or you could use dclone() from Storable: use Storable qw( dclone ); sub try { my @b = @{ dclone( \@_ ) }; ..

Re: sub local variable changes global variable.

2011-10-16 Thread JPH
Thanks! My script seems to work with dclone. Though the (deep) recursion takes a lot of time ... What is your opinion, would it pay off (in performance) when I rewrite the script in such a way that I do not use dclone, but string manipulation routines instead? So: - passing a single dimension

Re: sub local variable changes global variable.

2011-10-16 Thread JPH
You got me there, John. Indeed I do expect it to contain ' ' and not 0 like I stated. If you originally assign " " to $a[ 0 ][ 1 ] why would you now expect it to contain 0? John -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.

Re: sub local variable changes global variable.

2011-10-15 Thread John W. Krahn
JPH wrote: Hi all, Hello, I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub local is "

Re: sub local variable changes global variable.

2011-10-15 Thread Shawn H Corey
On 11-10-15 07:44 PM, Rob Dixon wrote: sub try { my @b; foreach my $row (@_) { push @b, [@$row]; } : } Or you could use dclone() from Storable: use Storable qw( dclone ); sub try { my @b = @{ dclone( \@_ ) }; ... } Storable is a standard modul

Re: sub local variable changes global variable.

2011-10-15 Thread Rob Dixon
On 16/10/2011 00:08, JPH wrote: Hi all, I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub

Re: sub local variable changes global variable.

2011-10-15 Thread Paul Johnson
On Sun, Oct 16, 2011 at 01:08:19AM +0200, JPH wrote: > Hi all, > > I am passin a two-dimensional array to a sub and when the sub This is your main problem. Perl doesn't have two-dimensional arrays. What it does have is arrays of array references which, if you squint, can be used as two-dimensio

sub local variable changes global variable.

2011-10-15 Thread JPH
Hi all, I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub local is "@b" - Why is this hap

Re: Help, About Global variable.

2011-09-15 Thread Shawn H Corey
On 11-09-14 11:18 PM, Brandon McCaig wrote: Personally I agree that it's very sloppy to write without capitals. I find it sloppy for people whose first language is English not to do their best. Many readers of this list do not have English as a their first language and the best way to improv

Re: Help, About Global variable.

2011-09-14 Thread Uri Guttman
> "BM" == Brandon McCaig writes: BM> [1] I personally find it very petty when Uri mentions his work as a BM> Perl "recruitment agent" (for lack of a better description right now) BM> and implies that he'll never consider you as a potential candidate BM> with regards to that because of

Re: Help, About Global variable.

2011-09-14 Thread Brandon McCaig
On Wed, Sep 14, 2011 at 8:57 PM, Uri Guttman wrote: > it was topical as your (self admitted) blowup happened here. and it > caused a small ruckus until you calmed down. I'd say you're both out to lunch on this. I don't even recall this subject so if I even read the affected threads then I obvious

Re: Help, About Global variable.

2011-09-14 Thread Uri Guttman
> "RD" == Rob Dixon writes: RD> On 14/09/2011 21:30, Uri Guttman wrote: >> >>> Uri we are all privileged with your thoughts on variable naming. My last >>> attempt to say that perhaps you weren't always right wrong resulted in a >>> personal attack saying "you had that blowup a few

Re: Help, About Global variable.

2011-09-14 Thread Rob Dixon
On 14/09/2011 21:30, Uri Guttman wrote: Uri we are all privileged with your thoughts on variable naming. My last attempt to say that perhaps you weren't always right wrong resulted in a personal attack saying "you had that blowup a few months ago. are you doing that again?" Given that you choos

Re: Help, About Global variable.

2011-09-14 Thread Jim Gibson
On 9/14/11 Wed Sep 14, 2011 5:04 AM, "William" scribbled: > On Sep 14, 5:39 am, chrisstinem...@gmail.com (Chris Stinemetz) wrote: ...For more information see: >> >>>        #!/usr/local/bin/perl >>>        use strict; >>>        $a = 1; >>>        $b = 2; >>>        print qq($a, $b\n); >

Re: Help, About Global variable.

2011-09-14 Thread William
On Sep 14, 5:39 am, chrisstinem...@gmail.com (Chris Stinemetz) wrote: > >> ...For more information see: > > >>http://perl.plover.com/FAQs/Namespaces.html > > > Useful article. > > > Now can you explain why I get no error with this little routine? - > > >        #!/usr/local/bin/perl > >        use

Re: Help, About Global variable.

2011-09-14 Thread Uri Guttman
> "RD" == Rob Dixon writes: RD> On 14/09/2011 16:51, Uri Guttman wrote: >>> "PJ" == Paul Johnson writes: >> PJ> On Tue, Sep 13, 2011 at 11:34:34PM -0400, Uri Guttman wrote: >> >> here is another good reason to stay aways from single letter var >> >> names. they are hard to

Re: Help, About Global variable.

2011-09-14 Thread Rob Dixon
On 14/09/2011 16:51, Uri Guttman wrote: "PJ" == Paul Johnson writes: PJ> On Tue, Sep 13, 2011 at 11:34:34PM -0400, Uri Guttman wrote: >> here is another good reason to stay aways from single letter var >> names. they are hard to search for as other vars which start with those >>

Re: Help, About Global variable.

2011-09-14 Thread Shawn H Corey
On 11-09-14 11:51 AM, Uri Guttman wrote: show me a tool that can search for single letter names cleanly and with little effort as compared to longer names. also this isn't the only reason, just one of several. ViM. Put the cursor on the variable and press * Also: press # to search backward.

Re: Help, About Global variable.

2011-09-14 Thread Uri Guttman
> "PJ" == Paul Johnson writes: PJ> On Tue, Sep 13, 2011 at 11:34:34PM -0400, Uri Guttman wrote: >> here is another good reason to stay aways from single letter var >> names. they are hard to search for as other vars which start with those >> letters will also be found. PJ> This may

Re: Help, About Global variable.

2011-09-14 Thread Paul Johnson
On Tue, Sep 13, 2011 at 11:34:34PM -0400, Uri Guttman wrote: > here is another good reason to stay aways from single letter var > names. they are hard to search for as other vars which start with those > letters will also be found. This may be the worst argument I have ever heard against using si

Re: Help, About Global variable.

2011-09-14 Thread William
On 9月13日, 下午8时33分, shlo...@shlomifish.org (Shlomi Fish) wrote: > Hello William, > > On Mon, 12 Sep 2011 20:05:38 -0700 (PDT) > > William wrote: > > My Code: > > use strict ; > > use warnings ; > > > chomp($input = ) ; > > > I compile this but has a error. say:Globla symbol "@input" requires > > ex

Re: Help, About Global variable.

2011-09-13 Thread Uri Guttman
> "JD" == John Delacour writes: JD> At 16:39 -0500 13/09/2011, Chris Stinemetz wrote: >>> From Learning Perl book: >> >> In some circumstances, $a and $b won't need to be declared, because >> they're used internally by sort. So if you're testing this feature, >> use other variabl

Re: Help, About Global variable.

2011-09-13 Thread John Delacour
At 16:39 -0500 13/09/2011, Chris Stinemetz wrote: From Learning Perl book: In some circumstances, $a and $b won't need to be declared, because they're used internally by sort. So if you're testing this feature, use other variable names than those two. The fact that use strict doesn't forbid the

Re: Help, About Global variable.

2011-09-13 Thread Chris Stinemetz
> >> ...For more information see: >> >> http://perl.plover.com/FAQs/Namespaces.html > > Useful article. > > Now can you explain why I get no error with this little routine? - > >        #!/usr/local/bin/perl >        use strict; >        $a = 1; >        $b = 2; >        print qq($a, $b\n); > >Fro

Re: Help, About Global variable.

2011-09-13 Thread John Delacour
At 15:33 +0300 13/09/2011, Shlomi Fish wrote: ...For more information see: http://perl.plover.com/FAQs/Namespaces.html Useful article. Now can you explain why I get no error with this little routine? - #!/usr/local/bin/perl use strict; $a = 1; $b = 2;

Re: Help, About Global variable.

2011-09-13 Thread Shlomi Fish
Hello William, On Mon, 12 Sep 2011 20:05:38 -0700 (PDT) William wrote: > My Code: > use strict ; > use warnings ; > > chomp($input = ) ; > > I compile this but has a error. say:Globla symbol "@input" requires > explicit package name at... Well, you didn't copy-and-paste the error correctly, b

Help, About Global variable.

2011-09-13 Thread William
My Code: use strict ; use warnings ; chomp($input = ) ; I compile this but has a error. say:Globla symbol "@input" requires explicit package name at... What should i do? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://le

Re: perl compilation issue - using global variable

2008-11-21 Thread ashish nainwal
I am using perlcc to compile perl script On Thu, Nov 20, 2008 at 8:25 PM, Chas. Owens <[EMAIL PROTECTED]> wrote: > On Thu, Nov 20, 2008 at 00:05, ashish nainwal <[EMAIL PROTECTED]> > wrote: > > Thanks for the info. I will be using my perl script for AIX but I am not > > able to find a supporting

Re: perl compilation issue - using global variable

2008-11-20 Thread Chas. Owens
On Fri, Nov 21, 2008 at 01:55, ashish nainwal <[EMAIL PROTECTED]> wrote: > I am using perlcc to compile perl script Yeah, that is a bad idea. from http://search.cpan.org/~nwclark/perl-5.8.8/utils/perlcc.PL: The code generated in this way is not guaranteed to work. The whole codegen suite (perlcc

Re: perl compilation issue - using global variable

2008-11-20 Thread Chas. Owens
On Thu, Nov 20, 2008 at 00:05, ashish nainwal <[EMAIL PROTECTED]> wrote: > do u have any such doc..please provide it to me! > > On Thu, Nov 20, 2008 at 10:35 AM, ashish nainwal > <[EMAIL PROTECTED]>wrote: > >> Thanks for the info. I will be using my perl script for AIX but I am not >> able to find

Re: perl compilation issue - using global variable

2008-11-20 Thread Chas. Owens
On Thu, Nov 20, 2008 at 00:05, ashish nainwal <[EMAIL PROTECTED]> wrote: > Thanks for the info. I will be using my perl script for AIX but I am not > able to find a supporting IBM official doc which says that AIX comes with > perl by default. snip What are you using to create the binary? PAR::Pack

Re: perl compilation issue - using global variable

2008-11-20 Thread ashish nainwal
Thanks for the info. I will be using my perl script for AIX but I am not able to find a supporting IBM official doc which says that AIX comes with perl by default. On Thu, Nov 20, 2008 at 10:32 AM, Mr. Shawn H. Corey <[EMAIL PROTECTED]>wrote: > On Thu, 2008-11-20 at 10:23 +0530, ashish nainwal wr

Re: perl compilation issue - using global variable

2008-11-20 Thread ashish nainwal
do u have any such doc..please provide it to me! On Thu, Nov 20, 2008 at 10:35 AM, ashish nainwal <[EMAIL PROTECTED]>wrote: > Thanks for the info. I will be using my perl script for AIX but I am not > able to find a supporting IBM official doc which says that AIX comes with > perl by default. > >

Re: perl compilation issue - using global variable

2008-11-20 Thread ashish nainwal
I want to compile a perl script because I want to run it on systems which dont have perl installed. Does creating an executable solve this purpose? If yes, then how can I do that? On Wed, Nov 19, 2008 at 10:38 PM, Mr. Shawn H. Corey <[EMAIL PROTECTED]>wrote: > On Wed, 2008-11-19 at 04:03 -0800, a

Re: perl compilation issue - using global variable

2008-11-19 Thread Mr. Shawn H. Corey
On Thu, 2008-11-20 at 10:23 +0530, ashish nainwal wrote: > I want to compile a perl script because I want to run it on systems > which > dont have perl installed. > Does creating an executable solve this purpose? If yes, then how can I > do > that? All versions of Linux, BSD and UNIX come with Per

Re: perl compilation issue - using global variable

2008-11-19 Thread Mr. Shawn H. Corey
On Wed, 2008-11-19 at 04:03 -0800, ashish wrote: > Can someone please tell me how to compile a perl script which is > calling global variables and then how should the executable be used? > There is no need to compile a Perl script. To run it, call it with perl: perl ftp.pl Or you can make it

perl compilation issue - using global variable

2008-11-19 Thread ashish
t;$loc")) { print "Changed to the directory $loc without any trouble \n"; } else { print "Could not change to $loc directory \n"; } if ($ftp->put("/home/ashish/perl/touch.tst","$ftploc/touch.test")) {print "file transferred properly \n"; }

Re: How to put a global variable in a package, accessible to usersof that package?

2008-11-01 Thread John W. Krahn
Dr.Ruud wrote: "Mr. Shawn H. Corey" schreef: 2) Perl does not have true constants. When you `use constant` you actually create a sub that returns a value. This: use constant VAR => "someval"; is the same as: sub VAR { return "someval"; } Perl has true constants. "use constant" isn't t

Re: How to put a global variable in a package, accessible to usersof that package?

2008-11-01 Thread Dr.Ruud
"Mr. Shawn H. Corey" schreef: > 2) Perl does not have true constants. When you `use constant` you > actually create a sub that returns a value. This: > > use constant VAR => "someval"; > > is the same as: > > sub VAR { > return "someval"; > } Perl has true constants. "use constant" isn't

RE: How to put a global variable in a package, accessible to users of that package?

2008-10-31 Thread Stewart Anderson
> -Original Message- > From: Rob Dixon [mailto:[EMAIL PROTECTED] > Sent: 31 October 2008 11:51 > To: Perl Beginners > Cc: Stewart Anderson > Subject: Re: How to put a global variable in a package, accessible to > users of that package? > > Stewart Anderson wro

Re: How to put a global variable in a package, accessible to users of that package?

2008-10-31 Thread Rob Dixon
Stewart Anderson wrote: >> From: mrstevegross [mailto:[EMAIL PROTECTED] >> >> I have a package named "Foo" in which I want to define some package- >> level constants (such as $VAR="soemval"). I want those constants >> available to users of package Foo, so the following code would work: >> >> === fo

RE: How to put a global variable in a package, accessible to users of that package?

2008-10-31 Thread Stewart Anderson
> -Original Message- > From: Jeff Pang [mailto:[EMAIL PROTECTED] > Sent: 31 October 2008 09:38 > To: Perl Beginners [Beginners Perl] > Subject: RE: How to put a global variable in a package, accessible to > users of that package? > > > > Message du 31

RE: How to put a global variable in a package, accessible to users of that package?

2008-10-31 Thread Jeff Pang
> Message du 31/10/08 10:25 > De : "Stewart Anderson" > A : "mrstevegross" , beginners@perl.org > > === foo.pl === > > package foo; > > use constant VAR => "someval"; > > > > === bar.pl === > > use foo; > > print $foo::VAR; > > > > It doesn't appear to be working; it compiles ok, but it prints >

RE: How to put a global variable in a package, accessible to users of that package?

2008-10-31 Thread Stewart Anderson
> From: mrstevegross [mailto:[EMAIL PROTECTED] > Sent: 30 October 2008 18:43 > To: beginners@perl.org > Subject: How to put a global variable in a package, accessible to users of > that package? > > I have a package named "Foo" in which I want to define some pack

Re: How to put a global variable in a package, accessible to users of that package?

2008-10-30 Thread Mr. Shawn H. Corey
On Thu, 2008-10-30 at 23:43 +, Rob Dixon wrote: > mrstevegross wrote: > > > > I have a package named "Foo" in which I want to define some package- > > level constants (such as $VAR="soemval"). I want those constants > > available to users of package Foo, so the following code would work: > > >

Re: How to put a global variable in a package, accessible to users of that package?

2008-10-30 Thread Rob Dixon
mrstevegross wrote: > > I have a package named "Foo" in which I want to define some package- > level constants (such as $VAR="soemval"). I want those constants > available to users of package Foo, so the following code would work: > > === foo.pl === > package foo; > use constant VAR => "someval";

How to put a global variable in a package, accessible to users of that package?

2008-10-30 Thread mrstevegross
I have a package named "Foo" in which I want to define some package- level constants (such as $VAR="soemval"). I want those constants available to users of package Foo, so the following code would work: === foo.pl === package foo; use constant VAR => "someval"; === bar.pl === use foo; print $foo:

Re: compiler output/global variable

2008-09-11 Thread Oliver Block
Hello Ray, Thanks for your response. I could already solve the problem. It was caused by a syntax error in a different line within the same sub.:-) I read my source code over and over and finally find the error. Best Regards, Oliver Block Am Donnerstag, 11. September 2008 16:30:49 schrieb Ra

Re: compiler output/global variable

2008-09-11 Thread John W. Krahn
Oliver Block wrote: hello everybody, Hello, what may cause perl to give the following command line output Global symbol "$form" requires explicit package name at /.../Address.pm line 44. even if the variable $form is declared in line 16 as follows my $form = $self->formbuilder;

Re: compiler output/global variable

2008-09-11 Thread Raymond Wan
Hi Oliver, You have to show more of the source code -- but it sounds like you've declared $form with "my" within a function/subroutine and it is not visible outside the function? Could that be the problem? Ray Oliver Block wrote: hello everybody, what may cause perl to give the followin

compiler output/global variable

2008-09-11 Thread Oliver Block
hello everybody, what may cause perl to give the following command line output Global symbol "$form" requires explicit package name at /.../Address.pm line 44. even if the variable $form is declared in line 16 as follows my $form = $self->formbuilder; within a sub of a class definit

Re: How to update value of global variable from child process (fork)

2007-10-10 Thread Jeff Pang
2007/10/10, dinesh <[EMAIL PROTECTED]>: > > Issue here is: The global associative array is not getting updated in > the child process. Please suggest me how to do this. childs and parent are separte,things changed on each process can't affect another. Say you have @global in parent,after forking,

Re: How to update value of global variable from child process (fork)

2007-10-10 Thread John W. Krahn
dinesh wrote: Hi, Hello, Subject: How to update value of global variable from child process (fork) The child and parent are separate processes so you have to use some type of InterProcess Communication to update values between them. perldoc perlipc John -- Perl isn't a toolbox,

How to update value of global variable from child process (fork)

2007-10-10 Thread dinesh
Hi, We need to run test in multiple test cycles and in each test cycle multiple operations need to be performed. Currently one test cycle is taking 10 seconds and we need to reduce the time to 4 seconds. I have used fork() to do this as follows (only one operation is given here). I will update the

Re: Global variable - No of hits counter

2007-01-22 Thread Mumia W.
On 01/22/2007 04:17 PM, tom tom wrote: Can I know how to pass parameters from the CRON job e.g cleanup folder and delta time in seconds and thereafter retreive that from the perl. My cleanup rountine currently hardcoded with these values [...] Why not just make it a regular, non-CGI, Perl sc

Re: Global variable - No of hits counter

2007-01-22 Thread tom tom
ome/lalitha/mod_cas/sessions',delta=>120, verbose => 0) -> expire_file_sessions(); --- "Mumia W." <[EMAIL PROTECTED]> wrote: > On 01/21/2007 04:55 PM, tom tom wrote: > > Hi, > > > > In my mod_perl (Authentication module). I have

Re: Global variable - No of hits counter

2007-01-21 Thread Mumia W.
On 01/21/2007 04:55 PM, tom tom wrote: Hi, In my mod_perl (Authentication module). I have global variable defined as follows use vars qw( $SESSION_CLEANUP_COUNTER); $SESSION_CLEANUP_COUNTER=0; my intention is to count no of times it is getting executed by clients (no of hits). I am

Global variable - No of hits counter

2007-01-21 Thread tom tom
Hi, In my mod_perl (Authentication module). I have global variable defined as follows use vars qw( $SESSION_CLEANUP_COUNTER); $SESSION_CLEANUP_COUNTER=0; my intention is to count no of times it is getting executed by clients (no of hits). I am incrementing it within Authenticate method as

Re: The Proper way to define a global variable.

2004-06-23 Thread Chris Welch
> From: John W. Krahn wrote: > Jason Corbett wrote: > > > > Hello. I am using variables that are local in my scripts by doing the my > > $variable_name technique. > > > > Can someone tell me if there is an official way to define a global variable? &

Re: The Proper way to define a global variable.

2004-06-22 Thread John W. Krahn
Jason Corbett wrote: > > Hello. I am using variables that are local in my scripts by doing the my > $variable_name technique. > > Can someone tell me if there is an official way to define a global variable? Perl doesn't really have "global" variables (like BASIC

Re: The Proper way to define a global variable.

2004-06-22 Thread Gunnar Hjalmarsson
Jason Corbett wrote: Can someone tell me if there is an official way to define a global variable? use vars qw($global1 $global2); or our ($global1, $global2); The latter cannot be used in Perl versions previous than 5.6.0. Note that the two methods do not do exactly the same thing; see

The Proper way to define a global variable.

2004-06-22 Thread jason corbett
Hello. I am using variables that are local in my scripts by doing the my $variable_name technique. Can someone tell me if there is an official way to define a global variable?

Re: global variable

2003-05-28 Thread Tassilo von Parseval
iFiles; $main::CFG = new Config::IniFiles( -file => "/path/configfile.ini" ); ... Uppercasing a global variable is a good idea to indicate that it is global. Now, if you want to access this variable from a module (that is, another namespace/package), all you have to know is in whi

global variable

2003-05-28 Thread anthony
Hi, i have a script with my modules. i.e #!/usr/bin/perl use strict; use warnings; use Config::IniFiles; my $cfg = new Config::IniFiles( -file => "/path/configfile.ini" ); use lib '/path/tomy/Module'; use MyModule; use TestModule; now i would like $cfg to be global , so that all module can use th

Re: How to make a local variable a global variable in Perl

2001-12-14 Thread Michael Fowler
On Wed, Dec 12, 2001 at 05:42:11PM +0100, Jorge Goncalvez wrote: > Hi I have this code: > ... > sub MakeEth() > { > unless ($_Globals{NICIP_ADRESS}==$IPREAL[0]) > { > $_Globals{ETH_NETIF} eq "eth0"; You must have meant "=", not "eq", as in: $_Globals{ETH_NETIF}

Re:How to make a local variable a global variable in Perl

2001-12-12 Thread Jorge Goncalvez
Hi I have this code: ... sub MakeEth() { unless ($_Globals{NICIP_ADRESS}==$IPREAL[0]) { $_Globals{ETH_NETIF} eq "eth0"; } else{ $_Globals{ETH_NETIF} eq "eth0:1"; } } ... sub StartDhcp() { my $_cmd = $_Os{$_Globa

Re: Help with global variable

2001-07-09 Thread dave hoover
Kailash wrote: [snip] Start each of your scripts with the following, it will save you many hours of debugging: #!/usr/bin/perl -w use strict; > $input = ; Declaring your variables with 'my' will help you keep track of their scope: my $input = ; > # I process the input here > # If the output

Help with global variable

2001-07-09 Thread Kailash . Subramanian
the variables, which are declared earlier (outside the sub routine), it is not working, obviously. Is there a way to declare a global variable so that I can refer to that variable inside a if loop or a sub-routine. I am sure there is a way. snippet of the code $input = ; # I process the input