PDA

View Full Version : File Fiddling Foulup


gorilla1
11-15-2002, 09:21 PM
When I run the code below from a telnet session and from within the same directory as this perl script and as the file junk.txt, I get the message "directory or file not found". What am I missing?

#!/usr/bin/perl

$new_file = "junk1.txt";

$old_file = "junk.txt";

renameStuff();


sub renameStuff {

rename($old_name,$new_name) or "Error renaming file ($old_name)\n";

exit();

}

mercurus
11-16-2002, 04:57 AM
G'day

Well, it could be a few things...

1) Double check the file locations.
Copy the junk.txt and the perl script to the same directory, change directory to this directory and execute the perl script.

2) Put -w as an option to the perl interpreter like so: #!/usr/bin/perl -w
It may give you more information.

3) Finally, add an error string variable to your die statement like so:
rename ($old_name,$new_name) || die "Error renaming file: $!\n";

Hope that helps track down the problem

Cheers
mercurus

gorilla1
11-17-2002, 03:17 PM
Thanks Mercurus. Yes, while I was in the right directory, it looks like the perl file was not named what I thought it was.

G