 Win32 platform need to understand the differences between the two platforms' paths. The two main differences are the delimiters and the case of the characters.
Delimiters. The most important difference between UNIX and Win32 paths is the delimiter that separates each segment of the path. In UNIX paths, a forward slash (/) delimits directories and files (e.g., /usr/bin/ foo.pl), whereas in Win32 paths, a backslash (\) is the delimiter (e.g., \temp\foo.pl). This distinction is important because Perl lets you use different delimiters to make porting scripts between platforms easier. Therefore, in Perl code, the UNIX path
@Statistics = stat( "/temp/foo.pl" );
is equivalent to the Win32 local path
@Statistics = stat( "\\temp\\foo.pl" );
Note the double backslashes in the Win32 local path. In Perl, you need to flag, or escape, a backslash with the escape character, which happens to be a backslash.
Interestingly, Perl lets you use single quotes (') as well as double quotes (") to enclose strings, including paths. However, single-quoted strings differ from double-quoted strings in two ways:
- Unlike double-quoted strings, single-quoted strings don't support interpretation of variables. In other words, the Perl interpreter doesn't expand variable names in single-quoted strings.
- Although you have to escape backslashes in double-quoted strings, you don't have to escape them in single-quoted strings. The Perl interpreter doesn't recognize escape sequences in single-quoted strings, except in two instances. First, the Perl interpreter recognizes the \' sequence (e.g., '\dave\'s script.pl) so that you can insert a single quote inside a single-quoted string. Second, the Perl interpreter recognizes the \\ sequence, which is useful when the sequence immediately precedes the ending single quote (e.g., '\temp\\'). This exception lets you insert a backslash at the end of a path. In this case, neither exception applies, so you can write the previous Win32 local path as
@Statistics = stat( '\temp\foo.pl' );
When you enclose a Win32 UNC path in single quotes, you run into a slight problem. The Perl interpreter reads the double backslash at the beginning of the UNC path as an escaped single backslash. The only workaround is to escape the first backslash in the pair with another backslash. Therefore, a UNC path in single quotes might look like
@Statistics = stat( '\\\server\temp\foo.pl' );
You handle double-quoted UNC paths similarly to single-quoted UNC paths. The only difference is that you need to escape every backslash:
@Statistics = stat( "\\\\server\\temp\\foo.pl" );
Although the Perl language lets you use Win32 or UNIX paths, many Perl extensions aren't as flexible, so using a path with forward slashes instead of backslashes would likely result in an error. Thus, when you write Perl code for Win32 OSs, a good rule of thumb is to follow Win32 conventions.
Character case. Unlike UNIX paths, Win32 paths are typically case insensitive. One exception might occur if you use an alternative (non-FAT16, non-FAT32, or non-NTFS) Installable File System (IFS) driver. You can develop an IFS driver that imposes case restrictions. For example, if your company has an NFS file-system driver, you might decide to impose case sensitivity. However, the default Win32 file systems (i.e., FAT16, FAT32, and NTFS) are case insensitive, so the code that Listing 1 shows is completely legal to use with those file systems.
In Listing 1, the first line lowercases the first parameter passed into the script, then assigns that parameter to the $Path variable. The call to the open() function works regardless of the case of the $Path variable's value.
DOS vs. Win32 Paths
In a legacy DOS platform, the file and directory names must be uppercase, exclude spaces, and follow the 8.3 format (i.e., the name can be up to eight characters long and the extension can be up to three characters long). In the Win32 platform, file and directory names can be mixed case, include spaces, and be much longer. Thus, a path such as C:\Program Files\My test file.txt is valid in Win32 but not DO