Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^4: Perl appending \ or / based on windows or linux

by kennethk (Abbot)
on Oct 07, 2014 at 20:39 UTC ( [id://1103111]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1103111]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-18 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found