CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
File::Find error message at runtime

 



adaykin
Novice

Jul 17, 2007, 11:49 AM

Post #1 of 6 (793 views)
File::Find error message at runtime Can't Post

I tried running my script and the command line gave me back this error at runtime. Invalid top directory at C:/perl/lib/file/find.pm at line 592. I use the module File::Find so I can process the directories recursively. Here is where I am going through the directories in my code:

Code
sub process_file  
{
# Search for all the TC's
my @files = grep {/^\d{3}/} readdir BIN;
close BIN;
# Go in and edit out the GUID field
foreach my $file(@files)
{
open(FILE, $guidFile) or die "$!";
readline FILE until eof FILE or $guidFile =~ /^GUID$/;
if($guidFile =~ /^GUID$/)
{
print "GUID Found";
}
}
}
find(\&process_file, @DIRLIST);


Not sure what to do about this error. I am on windows xp. To test I have been hard coding a directory in that has several files in it, and has a few directories beneath and on top of it.
------------------------------------------------------------

New Horizon Designs <-- My site, just updated the GUI to a PHP Nuke interface


(This post was edited by adaykin on Jul 20, 2007, 1:08 PM)


KevinR
Veteran


Jul 17, 2007, 1:56 PM

Post #2 of 6 (792 views)
Re: [adaykin] File::Find error message at runtime [In reply to] Can't Post

this:

find(\&process_file, my @DIRLIST);

should be:

find(\&process_file, @DIRLIST);

@DIRLIST has to be declared and defined before using it in the function.

Also, you can't "readline" the files becuase they are not opened:

readline until $file =~ /^GUID$/;
-------------------------------------------------


adaykin
Novice

Jul 18, 2007, 8:40 AM

Post #3 of 6 (789 views)
Re: [KevinR] File::Find error message at runtime [In reply to] Can't Post

ok inside of my foreach loop I have a syntax error I'm not sure which function is causing it:


Code
	foreach my $file(@files) 
{
open(FILE, my $guidFile)
readline FILE until eof FILE || FILE =~ /^GUID$/;
if(FILE =~ /^GUID$/)
{
print "GUID Found";
}
}

------------------------------------------------------------

New Horizon Designs <-- My site, just updated the GUI to a PHP Nuke interface


KevinR
Veteran


Jul 18, 2007, 10:15 AM

Post #4 of 6 (787 views)
Re: [adaykin] File::Find error message at runtime [In reply to] Can't Post

no semi-colon on the end of this line:

open(FILE, my $guidFile)

plus you can't declare $guidFile in the open function, it will have no value and the file will not open. Always check system functions for success or failure:

open(FILE, $guidFile) or die "$!";

but you need to declare and define $guidFile before using it in the open() function.
-------------------------------------------------


adaykin
Novice

Jul 20, 2007, 1:03 PM

Post #5 of 6 (777 views)
Re: [KevinR] File::Find error message at runtime [In reply to] Can't Post

ok I changed my code a bit but I am still getting the error. Here is my subroutine that tries to process everything below the current directory


Code
sub process_file  
{
# Search for all the TC's
my @files = grep {/^\d{3}/} readdir BIN;
close BIN;
# Go in and edit out the GUID field
foreach my $file(@files)
{
open(FILE, $guidFile) or die "$!";
readline FILE until eof FILE or $guidFile =~ /^GUID$/;
if($guidFile =~ /^GUID$/)
{
print "GUID Found";
}
}

}
find(\&process_file, @DIRLIST);

------------------------------------------------------------

New Horizon Designs <-- My site, just updated the GUI to a PHP Nuke interface


(This post was edited by adaykin on Jul 20, 2007, 1:09 PM)


KevinR
Veteran


Jul 20, 2007, 5:32 PM

Post #6 of 6 (772 views)
Re: [adaykin] File::Find error message at runtime [In reply to] Can't Post

read the File::Find documentation. You are not usng it correctly.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives