0

This is my code to handle file. I am having the file in my drive.

But I always getting file not found error. Do I need to give correct path ? Or Do the code will create a new file here ?

Why am I getting this error ?

Am I store the file in specific path ?

Do I missed anything to mention or Do I missed anything in the code ?

#open FH , ">>JEEVA.csv" or die "File not found"; #print FH $res1; #close FH; 
3
  • 5
    Do you have permission to write in the current directory? Also, you do not want to hard code the error message. You'll want to include the error $! variable, like so: or die "Cannot open JEEVA.csv for appending: $!"; And yes, the file should be created if it does not exist. Commented Dec 18, 2013 at 12:45
  • Generally speaking, its a rather bad idea to post a question and then not respond to it. Not only does it discourage people from participating in your problem, it also makes your answers less qualitative. Commented Dec 18, 2013 at 13:35
  • I can access another file which is there in the same directory. All the file having write permission... Commented Dec 19, 2013 at 6:00

3 Answers 3

6

Your program may not have permission to write to the file in the current directory. Make it print out the error message that explains why it couldn't open the file:

open FH, ">>JEEVA.csv" or die "could not write to JEEVA.csv: $!"; 
Sign up to request clarification or add additional context in comments.

Comments

1
open(my $fh, ">>", "JEEVA.csv") or die "Cannot open JEEVA.csv: $!"; print $fh $res1; close $fh; 

To go sure on FH.

Comments

0

Sometime environment path will not be set properly. So try to restart your pc. Then it may work. If this is not working, then we'll try to find another problem.

Comments