Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^6: shedding a bash wrapper and updating to Path::Tiny

by kevbot (Priest)
on Jul 26, 2018 at 04:23 UTC ( #1219294=note: print w/replies, xml ) Need Help??


in reply to Re^5: shedding a bash wrapper and updating to Path::Tiny
in thread shedding a bash wrapper and updating to Path::Tiny

Hello Datz_cozee75,

I'm glad you found my post helpful. I don't see mkdir used anywhere in your code. When you refer to mkdir, I assume you are referring to the mkpath method from Path::Tiny that you use in a couple places (not to be confused with the perl function mkdir). So, code like this may need to be changed to do what you want...

my $folder = path( $current, $to, $ts, $base_dir )->mkpath;
The documentation for the Path::Tiny mkpath method states that it returns the list of directories created or an empty list if the directories already exist, just like make_path.. So perhaps this would be more useful,
my $folder_path = path( $current, $to, $ts, $base_dir ); $folder_path->mkpath; # This will print the path regardless if the path already existed or n +ot print "My folder path is $folder_path\n";
If you wanted to check the return value of the mkpath method, you could store it in a scalar like this,
my $mkpath_return_value = $folder_path->mkpath; # The value of $mkpath_return_value will be equal to the number of dir +s created (since the return value will be a list that is forced into # scalar context), or it will be equal to zero if the path already exi +sted.
or if you wanted the list of dirs that were created you could do this,
my @dirs = $folder_path->mkpath;

Replies are listed 'Best First'.
Re^7: shedding a bash wrapper and updating to Path::Tiny
by Aldebaran (Chaplain) on Jul 26, 2018 at 20:04 UTC

    Gosh, kevbot, I try to be done making mistakes for one thread, so I hope that we can address this last one. Indeed, in my write-up I did conflate perl's mkdir with Path::Tiny's mkpath method. When one uses the latter in list context, one can build subsequent paths with it:

    my @dirs = path( $current, $to, $ts, $base_dir )->mkpath; say "dirs are @dirs"; foreach my $pchild ( $pop_from->children ) { my $base = $pchild->basename; say "base is $base"; my $to_name = path( @dirs, $base );

    I didn't find all that many examples for using Path::Tiny out there, so let's hope that others get something out of this.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2019-05-20 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (123 votes). Check out past polls.

    Notices?