On Wed, Oct 2, 2013 at 9:23 PM, Harry Putnam <rea...@newsguy.com> wrote: > Why is this script showing uninitialized variable warnings? > > ----- ------ ---=--- ------ ----- > #!/usr/local/bin/perl > > use strict; > use warnings; > use File::Find; > > my $exe = 33261; > my $eperm; > my $f = shift; > > find( sub { > return unless -f; > $eperm = (stat($File::Find::name))[2]; > if ($eperm eq $exe){ > print $File::Find::name . "\n"; > } > }, > $f > ); > ----- ------ ---=--- ------ ----- > > For every file it finds it also shows an uninitialized var warning. > > In a test directory of some 16 type -f files. > > Only 3 match the mode I'm after. > > The script outputs those 3 but then also 3 uninitialized var > warnings. > > ,---- > | script.pl . > | > | file1 > | file2 > | file3 > | Use of uninitialized value $eperm in string eq at ./fiex line 13. > | Use of uninitialized value $eperm in string eq at ./fiex line 13. > | Use of uninitialized value $eperm in string eq at ./fiex line 13. > `---- > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > >
Looks to me like $eperm is a variable inside the scope of the sub. That is used without using "my". Hope this helps. Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/