Re: An issue of Scope that I do not understand

2015-02-28 Thread Shlomi Fish
Hi Martin, here are some comments on your code in addition to what Uri said. On Fri, 27 Feb 2015 22:24:52 -0600 Martin G. McCormick mar...@server1.shellworld.net wrote: Brock Wilcox writes: I'm afraid a bit more context is needed to identify the problem. Could you post your entire bit of

Re: An issue of Scope that I do not understand

2015-02-28 Thread Martin G. McCormick
work after applying the following quote from your site: However, this is bad form in Perl, and the preferable way is to declare all the variables when they are first used, and at the innermost scope where they should retain their value. This will allow to keep track of them better

Re: An issue of Scope that I do not understand

2015-02-28 Thread Martin G. McCormick
Charles DeRykus writes: You could also simplify the closure since @tasks is in the closure's lexical scope, eg, my $report_static = sub { print $tasks[$iter++]; ... }; foreach $task (@tasks) { if (...) $report_statics-(); else $report_dynamic

Re: An issue of Scope that I do not understand

2015-02-28 Thread Shlomi Fish
, this is bad form in Perl, and the preferable way is to declare all the variables when they are first used, and at the innermost scope where they should retain their value. This will allow to keep track of them better. Again, thanks for creating this great resource. I hope I can stop

Re: An issue of Scope that I do not understand

2015-02-28 Thread Charles DeRykus
(@tasks) { if ( ) $report_static-(\@tasks); ... else $report_dynamic-(\@tasks); ... } } You could also simplify the closure since @tasks is in the closure's lexical scope, eg, my $report_static = sub { print $tasks[$iter

An issue of Scope that I do not understand

2015-02-27 Thread Martin G. McCormick
variables between subroutines but I just assumed that in an anonymous subroutine, one was still working with the same scope as the variables in the routine that called the subroutine. Thanks for any constructive suggestions. Martin McCormick -- To unsubscribe, e-mail: beginners-unsubscr

Re: An issue of Scope that I do not understand

2015-02-27 Thread Uri Guttman
On 02/27/2015 11:24 PM, Martin G. McCormick wrote: Brock Wilcox writes: I'm afraid a bit more context is needed to identify the problem. Could you post your entire bit of code into a gist or pastebin or something for us to see? I'll do better than that. This is a script which is

Re: An issue of Scope that I do not understand

2015-02-27 Thread Brock Wilcox
but I just assumed that in an anonymous subroutine, one was still working with the same scope as the variables in the routine that called the subroutine. Thanks for any constructive suggestions. Martin McCormick -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org

Re: An issue of Scope that I do not understand

2015-02-27 Thread Martin G. McCormick
Brock Wilcox writes: I'm afraid a bit more context is needed to identify the problem. Could you post your entire bit of code into a gist or pastebin or something for us to see? I'll do better than that. This is a script which is stripped of everything but the problem code. It is 20

Re: An issue of Scope that I do not understand

2015-02-27 Thread Charles DeRykus
On Fri, Feb 27, 2015 at 8:24 PM, Martin G. McCormick mar...@server1.shellworld.net wrote: Brock Wilcox writes: I'm afraid a bit more context is needed to identify the problem. Could you post your entire bit of code into a gist or pastebin or something for us to see? I'll do better

masks earlier declaration in same scope

2014-10-13 Thread Boylan, Ross
perl -c adduser gives its first error as my variable $new_uid masks earlier declaration in same scope at adduser line 283. First, it doesn't seem to me I'm declaring the variable at all at 283. I suppose it could be an implicit declaration if there wasn't a previous declaration

Re: masks earlier declaration in same scope

2014-10-13 Thread Charles DeRykus
On Mon, Oct 13, 2014 at 1:04 AM, Boylan, Ross ross.boy...@ucsf.edu wrote: perl -c adduser gives its first error as my variable $new_uid masks earlier declaration in same scope at adduser line 283. First, it doesn't seem to me I'm declaring the variable at all at 283. I suppose it could

RE: masks earlier declaration in same scope

2014-10-13 Thread Boylan, Ross
I think I figured out one thing from my earlier message: print '$template{uname}{ross} =' , $template{uname}{ross}, \n; #$template{uname}{ross} =ARRAY(0x20f41d8) # I'm still surprised this worked. Somehow we've gone 2 levels down with one $. print

RE: masks earlier declaration in same scope

2014-10-13 Thread Boylan, Ross
with scope, not statement). The if test at 284 checks if the user has specified an option giving the new uid and, if so, whether it is consistent with the template value. Finally, Did you really intend to declare and populate an array and throw in a conditional all in a one-liner? Yes. Do you

Re: Perl scope like cscope

2013-04-26 Thread Natal Ngétal
On 04/25/13 10:18, Jovan Trujillo wrote: I was just browsing through ack the other day. Have you checked that out? Same here I use a Vim plugin ack. -- \0/ Hobbestigrou site web: erakis.im -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail:

Re: Perl scope like cscope

2013-04-26 Thread Luca Ferrari
I use Emacs, so etags seems a natural choice for jumping across code. Luca -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Perl scope like cscope

2013-04-26 Thread shawn wilson
Yeah, I was going to suggest ctags. If you're using vim there's no good plugin for ctags (you'll try and I couldn't blame you but when vim starts blowing up make that the first plugin you disable). On Apr 26, 2013 4:13 AM, Luca Ferrari fluca1...@infinito.it wrote: I use Emacs, so etags seems a

Perl scope like cscope

2013-04-25 Thread kavita kulkarni
Hi, This could be naive. I use perl on linux and find it difficult to navigate quickly through the scripts. I wonder if there is something like cscope (which is very handy to navigate C code.) What are the standard practises in perl apart from normal grep or find like utilities? Any pointers

Re: Perl scope like cscope

2013-04-25 Thread Jovan Trujillo
I was just browsing through ack the other day. Have you checked that out? Ack: http://beyondgrep.com/ - Jovan On Thu, Apr 25, 2013 at 8:02 AM, kavita kulkarni kavitahkulka...@gmail.comwrote: Hi, This could be naive. I use perl on linux and find it difficult to navigate quickly through the

Re: Perl scope like cscope

2013-04-25 Thread senthil kumar
I too looking for this... and later on moved to Padre, the Perl IDE (easy to read and write code). - Original Message - From: kavita kulkarni kavitahkulka...@gmail.com To: beginners@perl.org Cc: Sent: Thursday, 25 April 2013 8:32 PM Subject: Perl scope like cscope Hi, This could

Re: Perl scope like cscope

2013-04-25 Thread WFB
, the Perl IDE (easy to read and write code). - Original Message - From: kavita kulkarni kavitahkulka...@gmail.com To: beginners@perl.org Cc: Sent: Thursday, 25 April 2013 8:32 PM Subject: Perl scope like cscope Hi, This could be naive. I use perl on linux and find it difficult

lexical scope

2012-06-05 Thread Chris Stinemetz
Why does this short program only seem to capture the last line of input in the @array, but when I put the for loop inside the while loop all lines of input are available in @array. I thought by declaring the @array outside the while loop would make all of its contents available once all the lines

Re: lexical scope

2012-06-05 Thread Robert Wohlfarth
On Tue, Jun 5, 2012 at 4:15 PM, Chris Stinemetz chrisstinem...@gmail.comwrote: Why does this short program only seem to capture the last line of input in the @array, but when I put the for loop inside the while loop all lines of input are available in @array. snip while ( my $line = DATA )

Re: lexical scope

2012-06-05 Thread Bill Stephenson
Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line = DATA ) { chomp $line; push (@array = split(/\s+/, $line,-1)); } for my $item ( @array ) { print $item,\n; } Kindest Regards, Bill Stephenson On Jun 5, 2012, at 4:15 PM, Chris Stinemetz

Re: lexical scope

2012-06-05 Thread Shawn H Corey
On 12-06-05 05:43 PM, Bill Stephenson wrote: Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line =DATA ) { chomp $line; push (@array = split(/\s+/, $line,-1)); push @array, [ split /\s+/, $line, -1 ]; } for my $item ( @array ) {

Re: lexical scope

2012-06-05 Thread Steve Bertrand
On 05/06/2012 3:49 PM, Shawn H Corey wrote: On 12-06-05 05:43 PM, Bill Stephenson wrote: Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line =DATA ) { chomp $line; push (@array = split(/\s+/, $line,-1)); push @array, [ split /\s+/, $line, -1

Re: lexical scope

2012-06-05 Thread Steve Bertrand
On 05/06/2012 6:31 PM, Steve Bertrand wrote: On 05/06/2012 3:49 PM, Shawn H Corey wrote: On 12-06-05 05:43 PM, Bill Stephenson wrote: Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line =DATA ) { chomp $line; push (@array = split(/\s+/,

Re: lexical scope

2012-06-05 Thread Shawn H Corey
On 12-06-05 08:31 PM, Steve Bertrand wrote: On 05/06/2012 3:49 PM, Shawn H Corey wrote: On 12-06-05 05:43 PM, Bill Stephenson wrote: Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line =DATA ) { chomp $line; push (@array = split(/\s+/,

Re: lexical scope

2012-06-05 Thread John W. Krahn
Chris Stinemetz wrote: Why does this short program only seem to capture the last line of input in the @array, but when I put the for loop inside the while loop all lines of input are available in @array. I thought by declaring the @array outside the while loop would make all of its contents

reading files and scope of $_

2011-02-24 Thread D
I ran into something that I need help understanding. In the attached script, subroutine file_proc1 converts all elements of @molec to undef, while file_proc2 does not. adjusting file_proc1 to first slurp the file into an array fixes it. My best guess (via dum_sub) is that the subroutine is

Re: reading files and scope of $_

2011-02-24 Thread John W. Krahn
D wrote: I ran into something that I need help understanding. In the attached script, subroutine file_proc1 converts all elements of @molec to undef, while file_proc2 does not. adjusting file_proc1 to first slurp the file into an array fixes it. My best guess (via dum_sub) is that the

Re: Redeclaration of variable [different scope]

2011-01-28 Thread Shawn H Corey
On 11-01-27 11:33 PM, Raymond Wan wrote: Oddly enough, when I run B::Xref through my scripts, I get segmentation faults I don't know if I'm using it incorrectly -- but on a simple Perl file, it works ok. And of course, it works ok with your one liner above. I get the same thing, even on

Redeclaration of variable [different scope]

2011-01-27 Thread Raymond Wan
Hi all, I was wondering if there is a way for Perl to give me a warning if I redeclare a variable in a different scope (and thus masking the outer one). Just spent some time debugging this (which was obviously not my intention to give two variables the same name)...and I guess it is a silly

Re: Redeclaration of variable [different scope]

2011-01-27 Thread C.DeRykus
On Jan 27, 1:51 am, r@aist.go.jp (Raymond Wan) wrote: Hi all, I was wondering if there is a way for Perl to give me a warning if I redeclare a variable in a different scope (and thus masking the outer one).  Just spent some time debugging this (which was obviously not my intention

Re: variable scope

2010-02-07 Thread Eric
value definitions int variables in a sub or another module and have them visible in the main:: scope as local variables. I once wrote a simple document for it, see:http://home.arcor.de/pangj/share_variables_between_perl_scripts.txt HTH. -- Jeff Peng Email: jeffp...@netzero.net Skype

Re: variable scope

2010-02-07 Thread Dr.Ruud
in the main:: scope as local variables. Use a hash. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

variable scope

2010-02-06 Thread Eric
I have a program that requests many config values from an ini file using Config::IniFiles. I import all of these values into my main:: script but it's pretty ugly. Is there a way to import my value definitions int variables in a sub or another module and have them visible in the main:: scope

Re: variable scope

2010-02-06 Thread Jeff Peng
them visible in the main:: scope as local variables. I once wrote a simple document for it, see: http://home.arcor.de/pangj/share_variables_between_perl_scripts.txt HTH. -- Jeff Peng Email: jeffp...@netzero.net Skype: compuperson -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org

Re: Global scope

2009-04-24 Thread Jay Savage
please don't top post... On Thu, Apr 23, 2009 at 2:18 PM, Vance E. Neff ven...@intouchmi.com wrote: snip Well it turns out that error was caused by some other problem.  I did not realize that our was not a function.  So you can't do something like this: our $variable = value1 if (something

Re: Global scope

2009-04-23 Thread Vance E. Neff
Gunnar, Thanks for your response! That is what I started with but then I was getting the error: xxx.pm: our variable $DataBaseType redeclared at xxx.pm line nn. Well it turns out that error was caused by some other problem. I did not realize that our was not a function. So you can't do

Global scope

2009-04-22 Thread Vance E. Neff
Hi, I'm trying to get some variables to be global in scope. I have declared a bunch of variables that I want to be accessible throughout my program. I have a module options.pm defined as: pre package options; use strict; use base qw(Exporter); our @EXPORT = qw(@BenefitsOptions

question on 2 sub modules on the same scope

2009-02-09 Thread itshardtogetone
Hi, Looking at the script below, can someone explain why the final output is Final = 1 instead of Final = 5. I thought at the end of the while loop, $a_ctr is 5, this value is then read by the sub module data() and this value of 5 is then passed on to sub publish before its being printed out.

Re: question on 2 sub modules on the same scope

2009-02-09 Thread John W. Krahn
itshardtogetone wrote: Hi, Hello, Looking at the script below, can someone explain why the final output is Final = 1 instead of Final = 5. I thought at the end of the while loop, $a_ctr is 5, this value is then read by the sub module data() and this value of 5 is then passed on to sub

Re: question on 2 sub modules on the same scope

2009-02-09 Thread David Shere
On Tue, 2009-02-10 at 02:55 +0800, itshardtogetone wrote: Hi, Looking at the script below, can someone explain why the final output is Final = 1 instead of Final = 5. I thought at the end of the while loop, $a_ctr is 5, this value is then read by the sub module data() and this value of 5 is

Re: question on 2 sub modules on the same scope

2009-02-09 Thread itshardtogetone
Original Message - From: David Shere dsh...@steelerubber.com To: itshardtogetone itshardtoget...@hotmail.com Cc: beginners@perl.org Sent: Tuesday, February 10, 2009 3:29 AM Subject: Re: question on 2 sub modules on the same scope What is an a_ctr, anyway? :) Thanks everyone

2 questions please, one on scope and one on regex

2008-12-22 Thread Eric Krause
Hello all, I have two quick questions that I would love some help on. I have looked at the manual (Programming Perl) and I didn't get it, hence my email. Question 1 - How can I make variables in a function (subroutine) global (accessible from other functions)? Question 2 - I am trying to

Re: 2 questions please, one on scope and one on regex

2008-12-22 Thread Mr. Shawn H. Corey
On Mon, 2008-12-22 at 15:18 -0700, Eric Krause wrote: Hello all, I have two quick questions that I would love some help on. I have looked at the manual (Programming Perl) and I didn't get it, hence my email. Question 1 - How can I make variables in a function (subroutine) global

Re: 2 questions please, one on scope and one on regex

2008-12-22 Thread John W. Krahn
Eric Krause wrote: Hello all, Hello, I have two quick questions that I would love some help on. I have looked at the manual (Programming Perl) and I didn't get it, hence my email. Question 1 - How can I make variables in a function (subroutine) global (accessible from other functions)?

Special Var with Name of current scope or name of subroutine?

2008-12-02 Thread Deviloper
Hi! Is there a special variable or trick to get the name of the current scope or subroutine name? Thanks, B.

Re: Special Var with Name of current scope or name of subroutine?

2008-12-02 Thread Chas. Owens
On Tue, Dec 2, 2008 at 09:11, Deviloper [EMAIL PROTECTED] wrote: Hi! Is there a special variable or trick to get the name of the current scope or subroutine name? Thanks, B. The caller* function will tell you information about the call stack (including the current function): #!/usr/bin

Re: Special Var with Name of current scope or name of subroutine?

2008-12-02 Thread Chas. Owens
On Tue, Dec 2, 2008 at 09:23, Chas. Owens [EMAIL PROTECTED] wrote: On Tue, Dec 2, 2008 at 09:11, Deviloper [EMAIL PROTECTED] wrote: Hi! Is there a special variable or trick to get the name of the current scope or subroutine name? Thanks, B. The caller* function will tell you

Re: Special Var with Name of current scope or name of subroutine?

2008-12-02 Thread Jenda Krynicky
From: Chas. Owens [EMAIL PROTECTED] On Tue, Dec 2, 2008 at 09:23, Chas. Owens [EMAIL PROTECTED] wrote: On Tue, Dec 2, 2008 at 09:11, Deviloper [EMAIL PROTECTED] wrote: Hi! Is there a special variable or trick to get the name of the current scope or subroutine name? Thanks, B

Re: Problem with scope in CGI script

2007-11-06 Thread Gunnar Hjalmarsson
John W . Krahn wrote: On Sunday 04 November 2007 18:06, Mike Martin wrote: sub run_cmd { return print print() returns either true or false. Why are you returning this value from your sub? span( { -class = 'place_cmd' }, submit( -name = 'action', -value = shift ) ), p }; ...

Re: Problem with scope in CGI script

2007-11-06 Thread John W . Krahn
On Tuesday 06 November 2007 00:24, Gunnar Hjalmarsson wrote: John W . Krahn wrote: On Sunday 04 November 2007 18:06, Mike Martin wrote: sub run_cmd { return print print() returns either true or false. Why are you returning this value from your sub? span( { -class = 'place_cmd' },

Re: Problem with scope in CGI script

2007-11-05 Thread Tom Phoenix
$list. See what happens when you give every variable the same name? Maybe you should use descriptive names for your variables, but in any case don't name a lexical with the same name as a global that you also wish to access in that scope, because the lexical takes precedence. Also, it helps

Re: Problem with scope in CGI script

2007-11-05 Thread John W . Krahn
On Sunday 04 November 2007 18:06, Mike Martin wrote: Hi Hello, I have the following script #!/usr/bin/perl -w use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use strict; use File::Basename; our $list; sub run_cmd { return print print() returns either true

Problem with scope in CGI script

2007-11-04 Thread Mike Martin
Hi I have the following script #!/usr/bin/perl -w use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use strict; use File::Basename; our $list; sub run_cmd {return print span({-class='place_cmd'},submit(-name='action', -value=shift)),p}; my %opts=(entry=\entry,

problem with variable scope

2007-10-22 Thread Siva Prasad
Hi Gurus, I have written a package as below. __PACKAGE package parseSite; use strict; use warnings; sub new { my $class = shift; my $Input_file=shift;

Re: problem with variable scope

2007-10-22 Thread Jeff Pang
On 10/22/07, Siva Prasad [EMAIL PROTECTED] wrote: while($FILE_H) { next unless /(div.*?\/tablebrbr)/; my @Rows=grep(/(div.*?\/tablebrbr)/,$FILE_H); return(@Rows); close $FILE_H; } Well,the first error I have noticed,you have lost a } in the code above. Have you run `perl -c

RE: problem with variable scope

2007-10-22 Thread Siva Prasad
Hi Gurus, I got the mistake which I was doing. Thanks a lot PP. _ From: Siva Prasad [mailto:[EMAIL PROTECTED] Sent: Monday, October 22, 2007 8:01 PM To: 'beginners@perl.org' Subject: problem with variable scope Hi Gurus, I have written a package as below

Re: problem with variable scope

2007-10-22 Thread Tom Phoenix
close() isn't a problem; since $FILE_H is a lexical variable, it's auto-closed when it goes out of scope. So I'd either put the close() before the return(), or omit it altogether. my $obj=grepsite-new(sample.txt); my @rows=$obj- GET_Values; $obj- Print_file(@rows); Use of uninitialized value

Re: problem with variable scope

2007-10-22 Thread Jenda Krynicky
From: Siva Prasad [EMAIL PROTECTED] while($FILE_H) { next unless /(div.*?\/tablebrbr)/; my @Rows=grep(/(div.*?\/tablebrbr)/,$FILE_H); return(@Rows); use HTML::TableExtract; Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song,

Variable scope

2007-10-02 Thread Beginner
Hi, I thought that the code snip below should work but I am not getting my text into the the file. The file is created but it's empty. Ideally I want to create the log file outside any sub routines so that $log to be available to any sub I have created and hence not scoped to any one sub

Re: Variable scope

2007-10-02 Thread Rob Dixon
Beginner wrote: I thought that the code snip below should work but I am not getting my text into the the file. The file is created but it's empty. Ideally I want to create the log file outside any sub routines so that $log to be available to any sub I have created and hence not scoped to

Re: Variable scope

2007-10-02 Thread Tom Phoenix
On 10/2/07, Beginner [EMAIL PROTECTED] wrote: Ideally I want to create the log file outside any sub routines so that $log to be available to any sub I have created and hence not scoped to any one sub routine. In other words, $log needs to be a global variable, so that it's available

Re: Variable scope

2007-10-02 Thread Beginner
On 2 Oct 2007 at 15:23, Rob Dixon wrote: Hi Dermot. You're a little confused, but you're not far out! Your being kind. $| = 1; I wasn't aware this only applied to STDOUT. My log messages all appear at once, when the script has exited and I was hoping for some 'realtime' messages.

RE: Variable scope

2007-10-02 Thread Bob McConnell
-Original Message- From: Beginner [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 02, 2007 10:39 AM To: perl beginners Subject: Re: Variable scope On 2 Oct 2007 at 15:23, Rob Dixon wrote: $| = 1; I wasn't aware this only applied to STDOUT. My log messages all

Re: Variable scope

2007-10-02 Thread Chas. Owens
On 10/2/07, Bob McConnell [EMAIL PROTECTED] wrote: snip $| = 1; I wasn't aware this only applied to STDOUT. My log messages all appear at once, when the script has exited and I was hoping for some 'realtime' messages. It used to be possible to turn off buffering on specific streams

Re: Variable scope

2007-10-02 Thread Chas. Owens
On 10/2/07, Beginner [EMAIL PROTECTED] wrote: snip $| = 1; I wasn't aware this only applied to STDOUT. My log messages all appear at once, when the script has exited and I was hoping for some 'realtime' messages. snip It applies to stdout because it is the currently selected filehandle.

RE: Scope

2006-10-02 Thread Derek B. Smith
Data::Dumper 'Dumper'; my $service; ($service) = (); print Dumper $service; John, For a complete understanding of scope (not listerine) : ) please read the following: http://perl.plover.com/local.html#2_Localized_Filehandles and http://www.perlmonks.org/?node_id=564448 Wow...opened my

Re: Scope

2006-10-02 Thread Chad Perrin
On Mon, Oct 02, 2006 at 07:15:38AM -0700, Derek B. Smith wrote: For a complete understanding of scope (not listerine) : ) please read the following: http://perl.plover.com/local.html#2_Localized_Filehandles and http://www.perlmonks.org/?node_id=564448 Wow...opened my eyes and I now

Scope

2006-10-01 Thread John Ackley
simple scope question when is a global not a global? or how to get a value from inside a while() to the outside? two tests-extracted from much large program to show my problem test 1 my $count; my $service; while( ($service) = $SERVICE

RE: Scope

2006-10-01 Thread Charles K. Clarkson
John Ackley wrote: : while( ($service) = $SERVICE-fetchrow_array ) { According to the DBI docs: If there are no more rows or if an error occurs, then fetchrow_array returns an empty list. When a value is returned, $service is set to that value. When we get to the end of the

comparing and contrasing two approaches to variable scope

2006-05-03 Thread Rance Hall
with local or some other scope defining declaration so that it would be available automatically in any and all subroutines called from the level you declared the var as local My question concerns a little of form and a little of function On the function front: which approach is faster

Re: comparing and contrasing two approaches to variable scope

2006-05-03 Thread Paul Johnson
subroutines that needed it with @_. Or you could declare that variable with local or some other scope defining declaration so that it would be available automatically in any and all subroutines called from the level you declared the var as local My question concerns a little of form and a little

Hashes and scope

2006-04-20 Thread Allister
be something to do with the way that I am assigning the key/value pairs to the hash, and possibly due to scope as well, but am unable to find out what I am doing wrong. Perhaps some kind person on the list could assist me. Excuse my code which is probably execrable. Thanks for any help

Re: Hashes and scope

2006-04-20 Thread Tom Phoenix
On 4/20/06, Allister [EMAIL PROTECTED] wrote: %qnums_quests = ($quest_number, $quest_string); The assignment operator replaces the entire variable on the left with the value on the right. If you wish to modify the hash, instead of replacing everything it contains, you probably want a statement

Re: Hashes and scope

2006-04-20 Thread Allister
On Thursday 20 April 2006 21:48, Tom Phoenix wrote: On 4/20/06, Allister [EMAIL PROTECTED] wrote: %qnums_quests = ($quest_number, $quest_string); The assignment operator replaces the entire variable on the left with the value on the right. If you wish to modify the hash, instead of

Re: scope of the variable?

2006-02-03 Thread Jeff Pang
$dbaccess; #the same as 'print $test::dbaccess;' -Original Message- From: [EMAIL PROTECTED] Sent: Feb 2, 2006 11:50 AM To: beginners@perl.org Subject: scope of the variable? Hello All, I have following question regarding accessing variable from other module: In test.pm I have following

Re: scope of the variable?

2006-02-03 Thread Bob Showalter
[EMAIL PROTECTED] wrote: ... My question is how to access $dbaccess variable (object) defined and initialized in test.pm within test2.pm module? If $dbaccess is delared with 'my' in test.pm, you cannot directly access it from another file. You have two basic options: 1. Provide an accessor

scope of the variable?

2006-02-02 Thread bogum
Hello All, I have following question regarding accessing variable from other module: In test.pm I have following: #BEGIN OF THE TEST.PM package test; use strict; use warnings; # # The object responsible for managing the database connections. # my $dbaccess = undef; -somewhere else $dbaccess

Re: about the var's scope

2006-01-16 Thread John Doe
Shawn Corey am Montag, 16. Januar 2006 04.12: [...] Ok, it would be interesting to look deeper into the mess of different variables all named with the same name $q, exported across the modules, overwritten by several imports... What do you want to achieve with your code? It looks really

Re: about the var's scope

2006-01-16 Thread Jeff Pang
. -Original Message- From: John Doe [EMAIL PROTECTED] Sent: Jan 16, 2006 4:09 AM To: beginners@perl.org Subject: Re: about the var's scope Shawn Corey am Montag, 16. Januar 2006 04.12: [...] Ok, it would be interesting to look deeper into the mess of different variables all named

Re: about the var's scope

2006-01-16 Thread Shawn Corey
Jeff Pang wrote: I think the only difference between the two is Stat's code do the things of sharing vars across modules really. Under mod_perl,the situation is very different from common CGI environment,and the vars sharing sometimes is useful and needed. I hope I'm correct.If not,the

about the var's scope

2006-01-15 Thread Jeff Pang
Hello,lists, Seeing these code below please.I can't know why the var defined in the main script can been accessed in the modules that used by the main script?thanks. script.pl: use vars qw($q); use CGI; use lib qw(.); use My::HTML qw($q); # My/HTML.pm is in the

Re: about the var's scope

2006-01-15 Thread Shawn Corey
Jeff Pang wrote: Hello,lists, Seeing these code below please.I can't know why the var defined in the main script can been accessed in the modules that used by the main script?thanks. From `perldoc vars`: While the vars pragma cannot duplicate the effect of package lexicals (total

Re: about the var's scope

2006-01-15 Thread Jeff Pang
Message- From: Shawn Corey [EMAIL PROTECTED] Sent: Jan 15, 2006 10:58 PM To: beginners@perl.org Subject: Re: about the var's scope Jeff Pang wrote: Hello,lists, Seeing these code below please.I can't know why the var defined in the main script can been accessed in the modules that used

Re: about the var's scope

2006-01-15 Thread John Doe
[reordered to bottom style posting] -Original Message- From: Shawn Corey [EMAIL PROTECTED] Sent: Jan 15, 2006 10:58 PM To: beginners@perl.org Subject: Re: about the var's scope Jeff Pang wrote: Hello,lists, Seeing these code below please.I can't know why the var defined

Re: about the var's scope

2006-01-15 Thread Jeff Pang
] Sent: Jan 16, 2006 9:48 AM To: beginners@perl.org Subject: Re: about the var's scope [reordered to bottom style posting] -Original Message- From: Shawn Corey [EMAIL PROTECTED] Sent: Jan 15, 2006 10:58 PM To: beginners@perl.org Subject: Re: about the var's scope Jeff Pang wrote

Re: about the var's scope

2006-01-15 Thread Shawn Corey
John Doe wrote: [reordered to bottom style posting] Jeff Pang am Montag, 16. Januar 2006 01.59: Thanks for Shawn.The main script can see the global var $q coming from module,since the main script import this symbol via 'use My::HTML qw($q)'.But the modules have no any importing behavior,why

Re: about the var's scope

2006-01-15 Thread John Doe
Shawn Corey am Montag, 16. Januar 2006 04.12: John Doe wrote: [reordered to bottom style posting] Jeff Pang am Montag, 16. Januar 2006 01.59: Thanks for Shawn.The main script can see the global var $q coming from module,since the main script import this symbol via 'use My::HTML

Re: about the var's scope

2006-01-15 Thread Jeff Pang
That's a good end for us all.Thanks for Shawn and John too. -Original Message- From: John Doe [EMAIL PROTECTED] Sent: Jan 16, 2006 2:09 PM To: beginners@perl.org Subject: Re: about the var's scope Shawn Corey am Montag, 16. Januar 2006 04.12: John Doe wrote: [reordered to bottom style

when do vars go out of scope in this case?

2005-12-06 Thread JupiterHost.Net
I just had a discussion about variables going out of scope (for memory considerations) The idea was presented that variables go out of scope as soon they're last referenced in a block, I always thought it was when the block ended. I was just about to search for this and thought I'd ask

Re: when do vars go out of scope in this case?

2005-12-06 Thread Shawn Corey
= load_100M_of_data(); print $foo; # $foo is using 100M of memeory ± } # memory for $foo has been released # A) $foo is now out of scope (and therefore no longer 100M of memory) since its not used anywhere after that print() in this block # 100 lines of code without any use of $foo

Re: when do vars go out of scope in this case?

2005-12-06 Thread JupiterHost.Net
. { { my $foo = load_100M_of_data(); print $foo; # $foo is using 100M of memeory ± } # memory for $foo has been released Good idea Shawn :) the actual project is one thing, I'm really mostly curious if that is true or not, that its out of scope when its last referenced in a block

Re: when do vars go out of scope in this case?

2005-12-06 Thread Wiggins d'Anconia
JupiterHost.Net wrote: I just had a discussion about variables going out of scope (for memory considerations) The idea was presented that variables go out of scope as soon they're last referenced in a block, I always thought it was when the block ended. When a var goes out of scope

Re: when do vars go out of scope in this case?

2005-12-06 Thread Shawn Corey
JupiterHost.Net wrote: Good idea Shawn :) the actual project is one thing, I'm really mostly curious if that is true or not, that its out of scope when its last referenced in a block instead of the end of a block. I still think at the end of the block. Going out-of-scope when last used

Re: when do vars go out of scope in this case?

2005-12-06 Thread Paul Johnson
project is one thing, I'm really mostly curious if that is true or not, that its out of scope when its last referenced in a block instead of the end of a block. In a language like Perl, it can be pretty hard to determine when a variable is last referenced. Here's a simple example. When is $h last

Re: when do vars go out of scope in this case?

2005-12-06 Thread JupiterHost.Net
:) the actual project is one thing, I'm really mostly curious if that is true or not, that its out of scope when its last referenced in a block instead of the end of a block. In a language like Perl, it can be pretty hard to determine when a variable is last referenced. Here's a simple example. When

Re: when do vars go out of scope in this case?

2005-12-06 Thread JupiterHost.Net
Wiggins d'Anconia wrote: JupiterHost.Net wrote: I just had a discussion about variables going out of scope (for memory considerations) The idea was presented that variables go out of scope as soon they're last referenced in a block, I always thought it was when the block ended. When

  1   2   3   >