in reply to Re: How to access a variable inside subroutine?
in thread How to access a variable inside subroutine?
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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to access a variable inside subroutine?
by Fletch (Bishop) on Sep 06, 2020 at 05:10 UTC | |
by LanX (Saint) on Sep 06, 2020 at 05:55 UTC | |
by tobyink (Canon) on Sep 06, 2020 at 09:04 UTC | |
by LanX (Saint) on Sep 06, 2020 at 09:42 UTC | |
by tobyink (Canon) on Sep 06, 2020 at 12:55 UTC | |
| |
|
Re^3: How to access a variable inside subroutine?
by pritesh_ugrankar (Monk) on Sep 05, 2020 at 21:08 UTC | |
by Anonymous Monk on Sep 06, 2020 at 22:37 UTC | |
|
Re^3: How to access a variable inside subroutine?
by perlfan (Parson) on Sep 05, 2020 at 20:51 UTC | |
by perlfan (Parson) on Sep 05, 2020 at 21:20 UTC |