update:Changed title at suggestion of beatnik
I re-encountered this the other day The following code pukes why?:
01: #!/usr/local/bin/perl -wT
03: open(FH,'data.txt')
04: or die "couldn't open file $!\n";
06: my $data_dir=<FH>;
07: chomp($data_dir);
08: close(FH)
09: or die "couldn't close file $!";
10: opendir(DH,$data_dir)
11: or die "couldn't open #$data_dir# $!\n";
12: my @files=readdir(DH)
13: or die "couldn't read dir\n";
14: print join("\n",@files);
Select the hints to view
HINT (contents of data.txt)
The data.txt contained a single line:
../
|
HINT (exact error message)
# No such file or directory
|
HINT (How the code was created)
All files were created in win2K notepad and ftp'd up to a LINUX box with DreamWeaver's check-in mechanism.
|
HINT (error message after removing a line)
After removing line 07 the error message became:
couldn't open #../
# No such file or directory
|
HINT (How the problem will be avoided in the future)
The following line was inserted between lines 07 and 08
$data_dir=~s/\r//g;
|
EXPLAINATION
Microsoft ends lines with a \r\n a carrage return and newline or \r\n.
UNIX ends them with a \n
When I read a line of text from my file, I accedently included a carrage return which became part of the directory name I was trying to open.
../\r is not a directory that exists on my LINUX system.
|