in reply to Re^3: Perl appending \ or / based on windows or linux
in thread Perl appending \ or / based on windows or linux

Rather than matching the separation character, match the directory names:
use strict; use warnings; use File::Spec::Functions qw(:ALL); use feature 'say'; my $testpath = catdir('foo','bar'); #say $testpath; my ($sepchar) = $testpath =~ m/^foo(.+)bar$/ or die 'Separation character identification failed'; say $sepchar;

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^5: Perl appending \ or / based on windows or linux
by Anonymous Monk on Oct 07, 2014 at 21:39 UTC

    Yes, you and dasgar are probably right, if one needs to get the directory separator out of File::Spec.

    The only caveat I have heard of is that on some OSes, paths aren't that easy... here's a sample VMS filename I found: DKA0:[MYDIR.SUBDIR1.SUBDIR2]MYFILE.TXT;1 - interesting!