use 5.030; use strict; use warnings; sub counter { my @nums = (1..500); state $add = 0; for my $num (@nums) { $add += $num; } sub getter { $add } # because this sub is inside the scope of coun +ter(), it has visibility on $add! } counter(); say "getter => ", getter();
In reply to Re^2: How to access a variable inside subroutine?
by pryrt
in thread How to access a variable inside subroutine?
by pritesh_ugrankar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |