C:\Users\tblaz>type 1.modules.pl
#!/usr/bin/perl
use warnings;
use 5.016;
use File::Find;
use Cwd;
=pod
=head1 DESCRIPTION
This is a pretty good first attempt at figuring out where your modules are. It is meant to follow the development of _Intermediate Perl_, and I will adhere to the idioms.
=cut
my $current = cwd;
find( \&pm_beneath, $current, );
say "--------------";
find( \&pm_beneath, "C:", );
sub pm_beneath {
use File::Basename;
my $basename = basename($File::Find::name);
return unless $basename =~ /\.pm$/;
print "$File::Find::name\n";
my $access_age = -A $basename;
print " $basename\n";
printf "access age in days: %.2f\n", $access_age;
}
__END__
C:\Users\tblaz>
####
Microsoft Windows [Version 10.0.17763.615]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\tblaz>perl 1.modules.pl >5.txt
...
at 1.modules.pl line 18.
Can't opendir(C:/Users/tblaz/Documents/My Pictures): Invalid argument
at 1.modules.pl line 18.
Can't opendir(C:/Users/tblaz/Documents/My Videos): Invalid argument
at 1.modules.pl line 18.
Can't opendir(C:/Users/tblaz/Local Settings): Invalid argument
at 1.modules.pl line 18.
Can't opendir(C:/Users/tblaz/My Documents): Invalid argument
at 1.modules.pl line 18.
Can't opendir(C:/Users/tblaz/NetHood): Invalid argument
at 1.modules.pl line 18.
Can't opendir(C:/Users/tblaz/PrintHood): Invalid argument
...
at 1.modules.pl line 20.
Can't opendir(C:Templates): Invalid argument
at 1.modules.pl line 20.
C:\Users\tblaz>
####
#!/usr/bin/perl -w
use 5.011;
use Path::Tiny;
use POSIX qw(strftime);
# initialization that must precede main data structure
# User: enter a subdirectory you would like to create
# enter a subdirectory of this^^^ for output
my $ts = "template_stuff";
my $output = "translations";
## turning things to Path::Tiny
my $abs = path(__FILE__)->absolute;
my $path1 = Path::Tiny->cwd;
my $path2 = path( $path1, $ts );
say "abs is $abs";
say "path1 is $path1";
say "path2 is $path2";
print "This script will build the above path2. Proceed? (y|n)";
my $prompt = ;
chomp $prompt;
die unless ( $prompt eq "y" );
my $template_file = "1.tags.tmpl";
my $abs_to_template = path( $path2, $template_file )->touchpath;
# script params
my %vars = (
monk_tags => path( $path2, $template_file ),
translations => path( $path2, $output ),
book => 'monastery tags ',
);
my $rvars = \%vars;
my $return1 = write_monk_tags($rvars);
say "return1 is $return1";
my $munge = strftime( "%d-%m-%Y-%H-%M-%S", localtime );
$munge .= ".monk.txt";
# use Path::Tiny to create and write to a text in relevant directory
my $save_file = path( $vars{$output}, $munge )->touchpath;
my $return2 = $save_file->spew_utf8($return1);
say "return2 is $return2";
say "created file $save_file";
# system("Run 'C:\Program Files (x86)\Notepad++\notepad++.exe' $save_file");
sub write_monk_tags {
use warnings;
use 5.011;
use Text::Template;
my $rvars = shift;
my %vars = %$rvars;
my $body = $vars{"monk_tags"};
my $template = Text::Template->new(
ENCODING => 'utf8',
SOURCE => "$body",
) or die "Couldn't construct template: $!";
my $return = "$vars{\"book\"}\n";
# User: change these quoted values for different order or tags
my @buchstaben = qw/i p c pre readmore b/;
for my $i (@buchstaben) {
$vars{"symbol"} = $i;
print "How many $i tag pairs would you like?: ";
my $prompt = ;
chomp $prompt;
if ( $prompt lt 1 ) {
$prompt = 0;
}
while ( $prompt gt 0 ) {
my $result = $template->fill_in( HASH => \%vars );
$return = $return . $result;
--$prompt;
}
}
return $return;
}
__END__