Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

Portability and use of forward slash in Perl file handling function arguments

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


public at khwilliamson

Nov 16, 2009, 6:25 PM

Post #1 of 4 (322 views)
Permalink
Portability and use of forward slash in Perl file handling function arguments

I am surmising that '/' is a reserved character in various Perl
functions, meaning the directory separator. I could not find any
documentation about this, and I don't have boxes to experiment on. 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.

I therefore think that this means that the slash is reserved, and other
system's different separators, like a ':' won't work.

What is the truth here? Is it documented anywhere?

Thanks


abigail at abigail

Nov 17, 2009, 12:30 AM

Post #2 of 4 (305 views)
Permalink
Re: Portability and use of forward slash in Perl file handling function arguments [In reply to]

On Mon, Nov 16, 2009 at 07:25:43PM -0700, karl williamson wrote:
> I am surmising that '/' is a reserved character in various Perl
> functions, meaning the directory separator. I could not find any
> documentation about this, and I don't have boxes to experiment on. 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.
>
> I therefore think that this means that the slash is reserved, and other
> system's different separators, like a ':' won't work.
>
> What is the truth here? Is it documented anywhere?


Perlport mentions directory separators in the section "Files and
Filesystems". It mentions various OSses that can work with '/' as a
directory separator. In fact,the only system it mentions that doesn't use
'/' is Mac OS, which, AFAIK, isn't supported by 5.10. (This doesn't mean
perlport says there aren't other OSses out there on which perl runs, and
where '/' cannot be used as a directory separator).



Abigail


ikegami at adaelis

Nov 17, 2009, 12:40 AM

Post #3 of 4 (298 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.


ikegami at adaelis

Nov 17, 2009, 12:44 AM

Post #4 of 4 (302 views)
Permalink
Re: Portability and use of forward slash in Perl file handling function arguments [In reply to]

On Tue, Nov 17, 2009 at 3:40 AM, Eric Brine <ikegami [at] adaelis> wrote:

> On Mon, Nov 16, 2009 at 9:25 PM, karl williamson <public [at] khwilliamson>wrote:
>
>> 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 simple example:

C:\>md d:\x\y

C:\>cd d:\x

C:\>perl -le"print -d 'd:y' ?1:0
1

C:\>rd d:\x\y

C:\>perl -le"print -d 'd:y' ?1:0
0

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.