in reply to distribution config file

I personally use __FILE__ to determine where the module is, and then determine the path seperator from that (although, I've never tested it on a non-unix system), and build the path to look at from there.

if (!defined($__registryDir)) { $__registryDir = __FILE__; ($__pathSeperator) = ($__registryDir =~ m/\bVSO\b(.*?)\bRegist +ry/ ); $__registryDir =~ s/\.pm$/${__pathSeperator}data/; }

(the module is 'Physics::Solar::VSO::Registry', so I know that the characters between 'VSO' and 'Registry' should be the path seperator).

I think there's a way to get the path seperator from the perl config, also.

Replies are listed 'Best First'.
Re^2: distribution config file
by rinceWind (Monsignor) on Jun 19, 2006 at 15:27 UTC

    There are two approaches to writing portable code to deal with paths. All systems running perl can cope with POSIX filenames, i.e. using '/' as a path separator. This works except when performing textual manipulation on a file spec in native format, though Windows can sometimes cope with a mixture of forward slashes and backslashes.

    The other approach is to use File::Spec, Cwd and friends in conjunction with the native syntax. If you do this, stick to native syntax throughout. Note that some OSes e.g. VMS, don't have a single 'path separator' but something more complicated.

    For more on this, see perldoc perlport and my YAPC portability talk slides.

    By the way, I don't think your approach will work in the OP's case.__FILE__ is an alias for $0 as far as I am aware, so this may not contain any path separators at all.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      "By the way, I don't think your approach will work in the OP's case.__FILE__ is an alias for $0 as far as I am aware, so this may not contain any path separators at all."

      "__FILE__ is the filename at that point in the program." -- Programming Perl.
      "$0 is the name of the program being executed." -- perldoc perlvar