CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Windows File Adressing



Jan 9, 2000, 9:23 PM

Post #1 of 3 (6207 views)
Windows File Adressing Can't Post

How does Perl access files on a windows platform? I know in unix it is (for example)

$path = "/home/www/blah"

but how is it done on a windows machine?

$path = "c:\home\www\blah"



Jan 9, 2000, 10:11 PM

Post #2 of 3 (6207 views)
Re: Windows File Adressing [In reply to] Can't Post


Actually, you can also use the first example you wrote on Win32:

$path = "/home/www/blah";

From "Learning Perl on Win32 Systems" Chapter 10.3 - Using Pathnames and Filenames:

"The only portable delimiter is the slash. Of course, if you're using drive letters, your script isn't really portable anyway.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

"c:\\temp" # backslash (escaped for double quoted string)
'c:\temp' # backslash (single quoted string)
"c:/temp" # slash - no escape needed </pre><HR></BLOCKQUOTE>

There are a couple of tradeoffs associated with either approach. First we look at the backslash: if you use the backslash to delimit paths, you have compatibilty problems with scripts that need to run on UNIX systems. You also need to remember to escape the backslash inside of double-quoted strings (or use single-quoted strings, because they are not interpolated). Finally, you need to remember to use a slash if you're outputting URL paths."

If you're going to be working on Win32, you may wish to pick up this book:

Learning Perl on Win32 Systems
By Randal L. Schwartz, Erik Olson & Tom Christiansen
1-56592-324-3, 306 pages
First Edition, August 1997


Jan 10, 2000, 10:59 AM

Post #3 of 3 (6207 views)
Re: Windows File Adressing [In reply to] Can't Post

Hi Ode,

I am not terribly familiar with Perl in Windows (I run Linux) but I know a little about it (I used to run Windows). The \ is an escape character in Perl so you can not use it like this. Your $path would be set like this
$path = 'C:\\home\\www\\blah';

You have to escape the escape so to speak Smile Other than that I don't remember any differences in the file path.

Hope this helped!


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives