Mr. Shawn H. Corey wrote:
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 ?
"follow"
Causes symbolic links to be followed. Since directory trees with
symbolic links (followed) may contain files more than once and
may even have cycles, a hash has to be built up with an entry for
each file. This might be expensive both in space and time for a
large directory tree. See follow_fast and follow_skip below. If
either follow or follow_fast is in effect:
· It is guaranteed that an lstat has been called before the
user’s "wanted()" function is called. This enables fast
file checks involving _. Note that this guarantee no
longer holds if follow or follow_fast are not set.
· There is a variable $File::Find::fullname which holds the
absolute pathname of the file with all symbolic links
resolved. If the link is a dangling symbolic link, then
fullname will be set to "undef".
This is a no-op on Win32.
Since the OP is not using the "follow" option then probably no to the
use of $File::Find::fullname.
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/