in reply to CPAN Module for mixing Unix/Windows path

Your makepath sounds like File::Spec's catdir. catdirwill return a consistent result, but the opposite of the one you asked for.

I suppose you could use filter the output of catdir as follows

use File::Spec::Functions qw( catdir ); sub lean_forw { my $s = @_ ? $_[0] : $_; $s =~ tr!\\!/!; return $s; } lean_forw(catdir('/home/foo/abc', 'bar\baz'))

Replies are listed 'Best First'.
Re^2: CPAN Module for mixing Unix/Windows path
by mandarin (Hermit) on Jun 05, 2008 at 12:27 UTC
    Maybe I misread your 'consistent', but for me
    use File::Spec::Functions qw( catdir ); print catdir('/home/foo/abc', 'bar\baz');
    gives
    /home/foo/abc/bar\baz
    which is not what I would have expected (i.e. either all forward or all backward slashes). This is perl 5.8.8. on linux

      Your test is invalid. File::Spec will never produce 'bar\baz'* on your system. Reread the OP.

      Update: I thought it went without saying given the context, but:
      * — where '\' is a path separator.

        I surely must be missing something here. In what way my test is invalid? I just was curious what catdir would do, so I downloaded your code, stripped the lean_forward sub and added a print statement.
        And was surprised by the output, as it contained a backslash.
        File::Spec will never produce 'bar\baz' on your system
        Well, it does. Double-checked it.
        'bar\baz' would make a valid unix filename, so maybe File::Spec does not render the '\' as a path seperator?