
ikegami at adaelis
Nov 17, 2009, 12:40 AM
Post #3 of 4
(322 views)
Permalink
|
|
Re: Portability and use of forward slash in Perl file handling function arguments
[In reply to]
|
|
On Mon, Nov 16, 2009 at 9:25 PM, karl williamson <public [at] khwilliamson>wrote: > I am surmising that '/' is a reserved character in various Perl functions, > meaning the directory separator. I only know of "require" that uses "/". When given a bareword module name, it replaces "::" with "/" to determine the path to the module. This makes its way into the %INC key. When given a path, it is treated opaquely: >type Foo.pm print __FILE__, "\n"; 1; >perl -e"require $_ for qw( Foo.pm ./Foo.pm ./Foo.pm ././Foo.pm );" Foo.pm ./Foo.pm ././Foo.pm I notice that the argument to 'require' can have slashes separating > directory components, and it appears to run portably. > > I also see a '-d $path' and $path seems to hold forward slashes which are > turned into the directory separator. > Those paths are passed opaquely to the OS. Perl doesn't know or care which bytes represent the directory separator. Note that Windows (the API) accepts both "\" and "/" interchangeably as directory separators. Some Windows command line tools do as well, but it varies by tools, and there is sometimes a requirement for the path to the quoted if it contains "/". > I therefore think that this means that the slash is reserved, and other > system's different separators, like a ':' won't work. > I would expect it to work. In fact, it does work perfectly fine in Windows as the device separator. One catch. I would expect "/" to be used for the keys of %INC on all systems, since it's a common assumption.
|