in reply to Re^2: Perl appending \ or / based on windows or linux
in thread Perl appending \ or / based on windows or linux
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl appending \ or / based on windows or linux
by kennethk (Abbot) on Oct 07, 2014 at 20:39 UTC | |
by Anonymous Monk on Oct 07, 2014 at 21:39 UTC |