Kevin Pfeiffer wrote:
>
> I would have thought that this would initialize my $indent variable to 2
> (like setting an initial state for an object), but if I call "indent()" I
> get nothing back. :-(
>
>
> { # static local variable
> my $indent = 2;
>
> sub indent {
> my $increment = shift;
> $indent += $increment if $increment;
> return $indent;
> }
> }
Well yes, it will, but only when you execute it. Take a look
at the program below.
HTH,
Rob
use strict;
use warnings;
printf "%d %d %d\n", indent(1), indent(2), indent(3);
{
my $indent = 2;
sub indent {
my $increment = shift;
$indent += $increment if $increment;
return $indent;
}
}
printf "%d %d %d\n", indent(1), indent(2), indent(3);
** OUTPUT **
1 3 6
3 5 8
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]