Is "require '/foo/bar/baz.pm'" portable?

J

J Krugman

Is something like

require '/path/to/some/Module.pm';

portable?

I could have sworn that there was a perlvar that contained the OS's
directory separator, but I can't find it, so either my memory is
playing me a trick, or this variable was eliminated at some point.

File::Spec is the generally accepted way to construct filenames
portably. But I have read in a couple of places that it is OK to
give Perl paths with the Unix directory separator like the one
above even in systems that don't use this separator. If this is
the case, then Perl must be doing the translation internally, which
would greatly diminish the utility of File::Spec, and make the
various OS-specific File::Spec::* modules all but useless.

What gives?

TIA!

jill
 
B

Brian McCauley

J said:
Is something like

require '/path/to/some/Module.pm';

portable?
Yes.

I could have sworn that there was a perlvar that contained the OS's
directory separator, but I can't find it, so either my memory is
playing me a trick, or this variable was eliminated at some point.

No, on some OSs it's not even as simple as a single character.
File::Spec is the generally accepted way to construct filenames
portably. But I have read in a couple of places that it is OK to
give Perl paths with the Unix directory separator like the one
above even in systems that don't use this separator. If this is
the case, then Perl must be doing the translation internally, which
would greatly diminish the utility of File::Spec, and make the
various OS-specific File::Spec::* modules all but useless.

What gives?

File::Spec is mostly needed for doing stuff like constructing arguments
for system() or parsing filenames passed into Perl in the OS's native
format.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top