On Sun, 2008-11-23 at 16:55 -0600, Harry Putnam wrote: > The program I'll post below is really only a test of a subroutine I > want to use in a larger program. Trying to get the subroutine ironed > out in this test script below so there is a little extra bumping > around to get it executed as sub routine, but It fails with these > errors: > > Variable "$rgx" will not stay shared at ./test line 30. > Global symbol "$finddir" requires explicit package name at ./test line > 19. > Execution of ./test aborted due to compilation errors. > > I don't understand why that happens. > > ------- 8< snip -------- > > #!/usr/local/bin/perl > > use strict; > use warnings; > > my $flag = shift; > > checkfile($flag); > sub checkfile { > use File::Find; > use File::MMagic; > use FileHandle; > > my ($rgx,$use,@finddir); > $use = shift @_; > $rgx = qr/(^|:)$use /; > @finddir = "/usr/portage/profiles"; > > find(\&wanted, @finddir) or die " Failed to open > finddir <$finddir>: $!";
You have not defined the scalar $finddir. You have defined the array @finddir, but it's not the same. > sub wanted { > my ($mm,$res,$testfile); > $testfile = $_; > $mm = new File::MMagic; # use internal magic file > $res = $mm->checktype_filename($testfile); > if ($res =~ /^plain\/text/) { > open(FILE,"<$File::Find::dir") or die "Can't open <$File::Find::dir>: > $!"; You can't open a directory. Should this be $File::Find::fullname ? > } > while(<FILE>) { > if (/$rgx/) { > print " $File::Find::dir\n"; > print " $_\n"; > } > } > } > } > > -- Just my 0.00000002 million dollars worth, Shawn The map is not the territory, the dossier is not the person, the model is not reality, and the universe is indifferent to your beliefs. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/