http://www.perlmonks.org?node_id=959041


in reply to file basics

What have you tried? First thing that comes to mind is to replace $fname with 'C:\perl_tests\test.txt'. Let's see what happens:
C:\Users\repellent>type C:\perl_tests\test.txt abc cde efg C:\Users\repellent>type t.pl #opening a file, checking the error code. $fname='C:\perl_tests\test.txt'; open xyz, $fname or die "Error in open:$!"; while(<xyz>){ print "line number $. is : $_"; } C:\Users\repellent>perl t.pl line number 1 is : abc line number 2 is : cde line number 3 is : efg

Hey, it just works!

Replies are listed 'Best First'.
Re^2: file basics
by harry1705 (Initiate) on Mar 12, 2012 at 01:15 UTC

    Thank you Mr.Repellent;At first i tried it with a file which already existed in the system thinking that it was a file with .txt extension.And then i got the error "file does not exist", so i decided to seek some help and hence posted my question modified, Got reply from you and tried to figure what was wrong, I found that the file which i used didn't have any extension on it. It now works.Thanks for enlightening me with What have you tried? and also for answering my dumb question

      The problem you probably ran into was that you used double quotes for your file name. (File extensions probably had nothing to do with it.) Since Windows's path separators are backslashes, and backslashes are a special character inside double quotes, this is many a beginner's stumbling-block. There are two easy fixes: use forward slashes (they work even on Windows), or use single quotes.

        Thanks Monk, Both these ways helped me solve the problem, but when i tried without file extensions i got the error "Error in open:no such file or directory" by using either forward slashes or single quotes in the windows path