Skip to content

this is nonsense

Ok, I have two files: and contents are as follows:

# this is a test program
# it tries to read the names of files in a directory to a file

print “Please enter the name of the directory you want to list.\n”;
print “Be careful of capitalization.\n”;
print “: “;

$dirname = <STDIN>;

# ok, i’ve got the name of the directory to read; now how about opening the output stream?

open(OUT, ‘> filelist.txt’) or die “can’t open file for output! $!”;

# what are the chances that eliminating the error handling code eliminates the error?
# nope, that just eliminated the error message. putting back the code.
opendir(DIR, $dirname) or die “can’t opendir $dirname: $!”;
while (defined($file = readdir(DIR))) {
# do something with “$dirname/$file”
print OUT $file . “\n”;

opendir(DIR, “.”); # . is the current directory

while ( $filename = readdir(DIR) ) {
print $filename , “\n”;

closedir DIR;

Then, I have output as follows:

C:\My Documents\programs\perl\musicfix\test>perl -w

C:\My Documents\programs\perl\musicfix\test>perl -w
Please enter the name of the directory you want to list.
Be careful of capitalization.
: .
can’t opendir .
: No such file or directory at line 16, line 1.

C:\My Documents\programs\perl\musicfix\test>

Somebody, anybody, please tell me why this doesn’t work. I’m tearing my hair out here.

RSS feed


No comments yet.

Sorry, the comment form is closed at this time.