You should be able to use a combination of File::Spec and a regex to dynamically determine what the seperation character is - provided that the regex contains all possible seperation characters.
use strict; use warnings; use File::Spec::Functions qw(:ALL); use feature 'say'; my $testpath = catdir('foo','bar'); #say $testpath; my $sepchar; ($sepchar) = ($testpath =~ m/(\\|\/)/); say $sepchar;
Not sure that this is any better than using $^O to determine the seperation character, but it one possible method using a core module. In either case, you still need to know the valid seperation characters for OSes that you intend to support. I guess the only advantage of the code above over using $^O is that you don't need to know the values of $^O for each OS.
In reply to Re^3: Perl appending \ or / based on windows or linux
by dasgar
in thread Perl appending \ or / based on windows or linux
by sravs448
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |