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: Intermediate: Re: [joeferns79] Error reading files from dir: Edit Log



Laurent_R
Veteran / Moderator

Feb 5, 2014, 10:43 AM


Views: 13186
Re: [joeferns79] Error reading files from dir


In Reply To
Couldn't open: A file or directory in the path name does not exist. at ./Summary.pl line 22.

Line 22 is ...

open my $out,'>',"report_${dir2}.txt" or die "Couldn't open: $!";


Well, it depends what the $dir2 variable contains. If it is a path containing backslashes such as, e.g. "/usr/bin", they you end up trying to create a file named "report_/usr/bin.txt" and the OS is unlikely to let you open such a file (that is unless your current directory has a "report_" subdirectory having itself a "usr" sub-subdirectory, in which case it will happily create a "bin.txt" file in that sub-subdirectory provided you have sufficient privileges to to it).

Print to the screen the name of the file you are trying create right before your open command or in the message passed to the die function, the origin of the problem will probably be obvious.

This is a general rule of debuging (in most programming languages): when some command fails, add a print statement before it with all the parameters used and run again (or you might use the Perl debugger).

In addition, you might have to filter out the "." and ".." directories at the beginning of your program, you certainly don't want to cd to them nor to open files with these names.


(This post was edited by Laurent_R on Feb 5, 2014, 10:54 AM)


Edit Log:
Post edited by Laurent_R (Veteran) on Feb 5, 2014, 10:51 AM
Post edited by Laurent_R (Veteran) on Feb 5, 2014, 10:52 AM
Post edited by Laurent_R (Veteran) on Feb 5, 2014, 10:54 AM


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

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