Respected Monks,
I am trying to print a variable in the subroutine outside the subroutine block.
use 5.030; sub counter { my @nums = (1..500); state $add= 0; for my $num(@nums) { $add += $num} } say "$add"; https://www.perlmonks.org/?node_id=11121379;displaytype=edit
I get an error stating "Global symbol "$add" requires explicit package name". How do I fix this? Kindly help.
In reply to How to access a variable inside subroutine? by pritesh_ugrankar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |