Last active
August 29, 2015 14:02
-
-
Save breezhang/c35f2465ca519dbbe190 to your computer and use it in GitHub Desktop.
package write dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use feature ':5.14'; | |
use Data::Dumper::Concise; | |
use Template; | |
use Carp qw /croak carp confess/; | |
use YAML; | |
my $whereconfig ; | |
my $Hash; | |
{ | |
local $/ = \8 * 1024; | |
open my $file, '<', $whereconfig || croak "fail open YAML file"; | |
$Hash = Load(<$file>); | |
close $file; | |
}; | |
my $base = $Hash->{base_path}; | |
my @newdirs = grep { !/base_path/ } keys $Hash; | |
makedir( \$base, \@newdirs ); | |
use File::Path qw(make_path remove_tree); | |
sub makedir { | |
my ( $p, $k ) = @_; | |
for my $t ( map { File::Spec->catfile( ${$p}, $_ ) } @{$k} ) { | |
make_path($t) unless -x $t; | |
} | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use feature ':5.14'; | |
use Data::Dumper::Concise; | |
use Template; | |
use Carp qw /croak carp confess/; | |
use YAML; # space not tab | |
my $whereconfig; | |
my $Hash; | |
{ | |
local $/ = \8 * 1024; | |
open my $file, '<', $whereconfig || croak "fail open YAML file"; | |
$Hash = Load(<$file>); | |
close $file; | |
}; | |
my $base = $Hash->{base_path}; | |
use File::Path qw(make_path remove_tree); | |
use File::Basename; | |
#refa refb refc | |
sub makedir { | |
my ( $p, $k, $h ) = @_; | |
for my $t ( map { File::Spec->catfile( ${$p}, $_ ) } @{$k} ) { | |
make_path($t) unless -x $t; | |
for my $tt ( @{ $h->{ basename($t) } } ) { | |
my $tp = File::Spec->catfile( $t, basename($tt) ); | |
store( $tt, $tp ) unless -x $tp; | |
} | |
} | |
return; | |
} | |
use LWP::Simple; | |
sub store { | |
my ( $url, $file ) = @_; | |
return getstore( $url, $file ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment