----- Original Message -----
From: "Gunnar Hjalmarsson" <[EMAIL PROTECTED]>
To: <beginners@perl.org>
Sent: Thursday, March 27, 2008 8:27 AM
Subject: Re: question on lexical declaration and submodule
.......
but I dont think this is a good idea as the sub-module will then have a
mixture of both lexical (my) and global variables.
No, they are both lexical, but in different scopes.
Thanks everyone for the help!
In a large program, I guess there may be many programmers involved and
each of these programmers are responsible to write their own sub rountine as
required. Henceforth it will be very confusing and problematic if the
programmers have to use variables from outside of their own sub-rountine.
Henceforth to prevent such confusion it is best to declare their variables
scope within their own sub-rountine. However, just like a counter, there are
times when we need to keep the values of these variables so that in the next
iteration such as in while function, I can add one to the counter whose
values was not discarded in the previous iteration thus changing the value
of the counter from 5 to 6... etc....
Therefore, if I wish to write a subroutine so that all its variables are
scope within his subroutine and yet I want to retain the values of some of
these variables for the next calling of this subroutine, I can write as
follows but I just wonder is this the best way :-
Also the script below produce the following warnings and so what must I
do to get rid of this warning.
The warning says "Use of uninitialized value $counter in numeric lt (<) at
C:/Documents and Settings/the solar system/Desktop/testing.pl line 16."
############################3
use strict;
use warnings;
my $anything = 0;
my $test_variable = 0;
while ($anything < 5){
$anything +=1;
$test_variable = &testing_module($test_variable) ;
}
sub testing_module {
my $counter = $_;
if ($counter < 5) {
$counter += 1;
}
$_ = $counter;
print "Counter counting $counter\n";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/