in reply to Re: Variable scope
in thread Variable scope
my $state; sub init_state { $state = shift } sub foo { if ($state) { ...
Where state makes sense, in my opinion, is in anonymous subs, because an anonymous sub has a defined life span:
for my $i (1 .. 3) { my $s = sub { state $x = $_; say "$i $x" }; $s->($_) for qw( a b ); }
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Variable scope
by shmem (Chancellor) on Apr 05, 2018 at 12:28 UTC | |
|
Re^3: Variable scope
by Anonymous Monk on Apr 06, 2018 at 09:19 UTC | |
|
Re^3: Variable scope
by Anonymous Monk on Apr 06, 2018 at 09:36 UTC | |
by choroba (Cardinal) on Apr 06, 2018 at 09:42 UTC | |
by Anonymous Monk on Apr 06, 2018 at 10:33 UTC | |
by choroba (Cardinal) on Apr 06, 2018 at 10:56 UTC | |
|
Re^3: Variable scope
by Anonymous Monk on May 15, 2018 at 17:11 UTC | |
by choroba (Cardinal) on May 15, 2018 at 17:51 UTC |