Your solution...
while ( 1 ) {
print 'main>';
chomp(my $main = <STDIN>);
my $yy = XYZ($main);
print "main $yy : $Last_Value\n";
}
exit(0);
{my $Last_Value = 'initial';
sub XYZ {
my $xyz = shift;
print "sub $xyz : $Last_Value\n";
$xyz = $Last_Value unless $xyz;
$Last_Value = $xyz;
return($xyz);
}
}
... is perfect. $Last_Value can't be printed in main. Now
my question is:
At first glance I thought the print in sub XYZ, would print 'initial' the first time thru, but it printed nothing for $Last_Value. Can you explain why?
while ( 1 ) {
print 'main>';
chomp(my $main = <STDIN>);
my $yy = XYZ($main);
print "main $yy : $Last_Value\n";
}
exit(0);
{my $Last_Value = 'initial';
sub XYZ {
my $xyz = shift;
print "sub $xyz : $Last_Value\n";
$xyz = $Last_Value unless $xyz;
$Last_Value = $xyz;
return($xyz);
}
}
... is perfect. $Last_Value can't be printed in main. Now
my question is:
At first glance I thought the print in sub XYZ, would print 'initial' the first time thru, but it printed nothing for $Last_Value. Can you explain why?