Hi,
I am doing some studies on sub modules and Lexical variables (my).
With regards to diagram 1 below, what can I do so that the lexical $counter can
count up to 4.
Of course, one way of doing this is to change the lexical $counter into a
global variable as seen in diagram 2 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.
So, are there any other ways of writing in diagram 1 so that the $counter can
count up to 4?
Thanks
############## Diagram 1 ---- lexical $counter t###############
use strict;
my $anything = 0;
while ($anything < 5){
$anything +=1;
&testing_module ;
}
sub testing_module {
my $counter = ();
if ($counter < 5){
$counter += 1;
}
}
###########################################
############# Diagram 2 -------- global $counter below ######################
use strict;
my $anything = 0;
my $counter = (); #global counter
while ($anything < 5){
$anything +=1;
&testing_module ;
}
sub testing_module {
$counter = ();
if ($counter < 5){
$counter += 1;
}
}