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. Thanks



#!/usr/bin/perl
use strict;
use warnings;

{
my $a_ctr = 0;

 sub data {
       $a_ctr = @_;
    }

  sub publish{
     print "Final = $a_ctr\n";
    }
}
#########################
my $a = 5;
my $a_ctr = 0;

while ($a_ctr < $a){
 $a_ctr ++;
    print "a_ctr = $a_ctr\n";
    &data($a_ctr);
}
&publish();

Reply via email to