philiprbrenan has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use v5.22; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump); my @n = 1..2; sub load {return my @a unless @n; push @a, @n; @a } say "$_ ", dump([load()]) for 1..10; =pod 1 [1, 2] 2 [1, 2, 1, 2] 3 [1, 2, 1, 2, 1, 2] 4 [1, 2, 1, 2, 1, 2, 1, 2] 5 [1, 2, 1, 2, 1, 2, 1, 2, 1, 2] 6 [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] 7 [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] 8 [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] 9 [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] 10 [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-l +inux-gnu-thread-multi =cut
Surely @a is local to sub load?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Surely @a is local to sub load?
by choroba (Cardinal) on Jun 26, 2016 at 23:07 UTC | |
by ikegami (Patriarch) on Jun 27, 2016 at 18:30 UTC | |
by choroba (Cardinal) on Jun 27, 2016 at 19:15 UTC | |
by philiprbrenan (Monk) on Jun 27, 2016 at 01:17 UTC |