Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: file basics

by repellent (Priest)
on Mar 11, 2012 at 22:33 UTC ( #959041=note: print w/replies, xml ) Need Help??

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 #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 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://959041]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2020-09-27 04:38 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (142 votes). Check out past polls.