Connecting Tech Pros Worldwide Forums | Help | Site Map

Opening a Windows file

Newbie
 
Join Date: Oct 2006
Posts: 2
#1: Oct 10 '06
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

Newbie
 
Join Date: Oct 2006
Posts: 2
#2: Oct 10 '06

re: Opening a Windows file


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

But of course.... ??????
Newbie
 
Join Date: Sep 2006
Posts: 23
#3: Oct 10 '06

re: Opening a Windows file


Quote:

Originally Posted by slawson7

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
miller's Avatar
Moderator
 
Join Date: Oct 2006
Location: San Francisco, CA
Posts: 830
#4: Oct 16 '06

re: Opening a Windows file


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.  
Newbie
 
Join Date: Nov 2006
Posts: 5
#5: Nov 16 '06

re: Opening a Windows file


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

Thanks
Reply