By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,703 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,703 IT Pros & Developers. It's quick & easy.

Opening a Windows file

P: 2
Easy one for all you Perl gurus out there.

I'm opening a text file, reading the contents into an array, doing some processing and spitting out the results to another file. Although I've got this working fine, I had to employ a workaround when opening the file originally.

I wanted to put:
open(INPUT, "d:\pscripts\input.txt")
or die "Could not open file for reading $!\n";

but when I executed this, it kept dying on me, saying that it couldn't find the file. Eventually, I had to put my input file in the same directory as the script (my workaround) and remove the path from the "open" command above.

It works, but it's bugging me. Why wouldn't it work with the full path?

TIA
Oct 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: 2
S'OK - figured it out. The slashes in the Windows path name have to go the other way.

But of course.... ??????
Oct 10 '06 #2

P: 23
S'OK - figured it out. The slashes in the Windows path name have to go the other way.

But of course.... ??????

because perl on windows follows the unix like paths.

infact in internally trnsalate every path according to unix file system
Oct 10 '06 #3

miller
Expert 100+
P: 1,089
Your previous code would have worked too, but you needed to escape the backslashes:

Expand|Select|Wrap|Line Numbers
  1. open(INPUT, "d:\\pscripts\\input.txt")
  2. or die "Could not open file for reading $!\n";
  3.  
or used single quotes so that the string was not interpolated:

Expand|Select|Wrap|Line Numbers
  1. open(INPUT, 'd:\pscripts\input.txt')
  2. or die "Could not open file for reading $!\n";
  3.  
Oct 16 '06 #4

P: 5
Hi,
I am trying to do a similar thing.
Can you help me sharing your code?

Thanks
Nov 16 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.