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

Thx haukex, I think I'm calling the mkdir method properly in this script so far. I'm getting alright partial results but want to cast the final solution in the idioms of Path::Tiny. Could I save myself the mkdir call by using the module better with the touchpath method?

I don't seem to know how to refer to the "children" I've created other than by "$_". First, output:

$ ./4.clone.pl 2.med 1.ert 2.med ------------- making directories ------------- copying files matching is 5.unicode1.css a is /home/bob/1.scripts/pages/2.med/template_stuff/5.unicode1.css b is 0/5.unicode1.css matching is utils1.pm a is /home/bob/1.scripts/pages/2.med/template_stuff/utils1.pm b is 0/utils1.pm ... matching is code1.tmpl a is /home/bob/1.scripts/pages/2.med/template_stuff/code1.tmpl b is 0/code1.tmpl ... ^^^zeroes here on the path for b, why? default is /home/bob/1.scripts/pages/2.med/template_stuff/5.unicode1.c +ss default is /home/bob/1.scripts/pages/2.med/template_stuff/utils1.pm default is /home/bob/1.scripts/pages/2.med/template_stuff/5.txt ... default is /home/bob/1.scripts/pages/2.med/template_stuff/footer_cente +r.txt default is /home/bob/1.scripts/pages/2.med/template_stuff/config1.pm default is /home/bob/1.scripts/pages/2.med/template_stuff/code1.tmpl $

What gives with the path for b having that o at the front? Source listing:

$ cat 4.clone.pl #!/usr/bin/perl -w use strict; use 5.010; use utf8; use open qw/:std :utf8/; use Path::Tiny; # This script clones the template directory in $1 to $2. # Some names need munging. # $from is a populated child directory; $to is child dir to be create +d. $pop is the folder with the data. my ( $from, $to, $pop ) = @ARGV; my $ts = "template_stuff"; my $current = path(".")->absolute; #say "current is $current"; say "-------------"; say "making directories"; # make root directory of clone: my $rd1 = path( $current, $to )->mkpath; # define the paths within the target directory: my $rd3 = path( $current, $to, $ts )->mkpath; # $from template directory: my $rd6 = path( $current, $from, $ts ); say "-------------"; say "copying files"; opendir my $eh, $rd6 or die "dead $!\n"; while ( defined( $_ = readdir($eh) ) ) { if (m/(txt|pm|css|tmpl|pl|sh)$/) { say "matching is $_"; $a = path( $rd6, $_ ); say "a is $a"; $b = path( $rd3, $_ ); say "b is $b"; #copy( $a, $b ); #path( $rd6, $_ )->copy($b); } } # for ( $dir->children ) { ... } for ( $rd6->children ) { say "default is $_"} #my $iter = $rd6->iterator; #while ( my $next = $iter->() ) { say "default is $_"} $

I'm looking for a way to loop through this file copy like a grown-up and be able to establish permissions on the files copied according to their endings following the usual conventions of what consituents an executable.