Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: filesystem path concatenation

by RichardK (Parson)
on Sep 28, 2015 at 14:58 UTC ( #1143259=note: print w/replies, xml ) Need Help??


in reply to Re: filesystem path concatenation
in thread filesystem path concatenation

Or even File::Spec which is a core module :-

$path = File::Spec->catfile( @directories, $filename );

Replies are listed 'Best First'.
Re^3: filesystem path concatenation
by Your Mother (Bishop) on Sep 28, 2015 at 22:52 UTC

    I prefer the higher level of abstraction with the same accurate portability by far :P

    moo@cow~>perldoc -m Path::Tiny | ack File::Spec use File::Spec 3.40 (); my $cpath = $path = File::Spec->canonpath($path); #pod Gives you C<< File::Spec->rootdir >> as a C<Path::Tiny> object if + you're too sub rootdir { path( File::Spec->rootdir ) } @{$self}[ VOL, DIR, FILE ] = File::Spec->splitpath( $self->[PATH] +); #pod in L<File::Spec> would normally do so on your platform. If you n +eed them #pod like C<catfile> or C<catdir> from File::Spec, but without caring +about #pod C<< File::Spec->splitpath( $path->stringify ) >> or C<"."> for a +path without a #pod parent directory portion. Because L<File::Spec> is inconsistent, + the result #pod C<< File::Spec->abs2rel() >>. # Easy to get wrong, so wash it through File::Spec (sigh) sub relative { path( File::Spec->abs2rel( $_[0]->[PATH], $_[1] ) ) } #pod equivalent to what L<File::Spec> would give from C<splitpath> and + thus friendlier to use than L<File::Spec> and provides easy access to funct +ions from Gives you C<< File::Spec->rootdir >> as a C<Path::Tiny> object if you' +re too in L<File::Spec> would normally do so on your platform. If you need t +hem like C<catfile> or C<catdir> from File::Spec, but without caring about C<< File::Spec->splitpath( $path->stringify ) >> or C<"."> for a path +without a parent directory portion. Because L<File::Spec> is inconsistent, the +result C<< File::Spec->abs2rel() >>. equivalent to what L<File::Spec> would give from C<splitpath> and thus
Re^3: filesystem path concatenation
by noname (Sexton) on Sep 29, 2015 at 09:15 UTC
    I see, thank you all !
Re^3: filesystem path concatenation
by sundialsvc4 (Abbot) on Sep 28, 2015 at 20:14 UTC

    File::Spec is definitely The Right Way™ to do this, because it is both purposeful and portable.   You really don’t want to have to be mucking-around with slashes, do you?   Worrying whether they ought to be forward or backward on this system or that?   Naww-w-w-ww, not if someone else has already done it for you!   And, since it is in the Core, you don’t have to install it:   it is already there.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2018-09-18 17:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (160 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!