The following code clearly shows what is going on. When you call foo for the first time, @a was shared by bar. Second time when you enter foo, bar does not share the new @a, instead it retains the old one.
use strict; use warnings; use Data::Dumper; foo(1); bar(); foo(2); bar(); sub foo { my @a; push @a, shift; print \@a; print Dumper(\@a); sub bar { print \@a; print Dumper(\@a); } }
Here is the output:
Variable "@a" will not stay shared at c.pl line 17.
ARRAY(0x1890e78)$VAR1 = [ 1 ]; ARRAY(0x1890e78)$VAR1 = [ 1 ]; ARRAY(0x18c2194)$VAR1 = [ 2 ]; ARRAY(0x1890e78)$VAR1 = [ 1 ];
Make @a_files a property of the class, and define those two methods at the same level. This shall resolve your problem, and the code is much clearer.
In reply to Re: Confused scoping while using File::Find
by pg
in thread Confused scoping while using File::Find
by rongoral
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |