471,854 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,854 software developers and data experts.

Opening a Windows file

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
4 18403
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
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
1,089 Expert 1GB
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
nmadpl
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.

Similar topics

2 posts views Thread by EP | last post: by
5 posts views Thread by albo | last post: by
14 posts views Thread by W Marsh | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.