Hello Monks
I've been deeply ensconced in getting some relatively-minor and low-level details squared away, but I find it hugely technical and unpredictable as I try to grasp what is happening at my terminal. In order to share it properly, it has to be pasted into a text document. Under such circumstances, I like having pairs of code tags at the ready. One can edit them later on. I seem to do better when I start the write-up early, especially with mystifying and hard-to-replicate output.
Likewise, a handful of p tags are necessary, and why not line them all up in shiny rows, so that we can see their completeness and symmetry. A short interview with this program gets you the tags you need. How many times have you created the tags from scratch and bolloxed it up? Machines can do it better.
Output then source:
$ ./2.ping1.pl
basename is 2.ping
path1 is /home/bob/2.scripts/pages/2.ping
abs is /home/bob/2.scripts/pages/2.ping/2.ping1.pl
variable is переменн&#
+1072;я
переменная
+ is variable
How many i tag pairs would you like?: 2
How many p tag pairs would you like?: 5
How many c tag pairs would you like?: 3
How many readmore tag pairs would you like?: 1
How many b tag pairs would you like?: 1
return1 is monk tags :
... [russian doesn't render in code tags]
return2 is 1
$ cat 2.ping1.pl
#!/usr/bin/perl -w
use 5.011;
use lib "template_stuff";
use html7;
use trans1;
use Path::Tiny;
use utf8;
use Encode;
use open OUT => ':encoding(UTF-8)', ':std';
use POSIX qw(strftime);
binmode STDOUT, ":utf8";
# initializations that must precede main data structure
my $ts = "template_stuff";
my $images = "aimages";
my $captions = "captions";
my $ruscaptions = "ruscaptions";
## turning things to Path::Tiny
# decode paths
my $abs = path(__FILE__)->absolute;
my $path1 = Path::Tiny->cwd;
my $title = $path1->basename;
$abs = decode('UTF-8', $abs);
$path1 = decode('UTF-8', $path1);
$title = decode('UTF-8', $title);
say "basename is $title";
say "path1 is $path1";
say "abs is $abs";
my $path2 = path( $path1, $ts );
# page params
my %vars = (
monk_tags => path( $path2, "1.monk.tmpl" ),
translations => path( $path2, 'translations' ),
book => 'monk tags ',
chapter => 'монах те&
+#1075;и',
server_dir => 'perlmonks',
image_dir => 'pmimage',
);
my $variable = "переменl
+5;ая";
say "variable is $variable";
my $переменна
+103; = "variable";
say "переменна&#
+1103; is $переменн
+072;я";
my $rvars = \%vars;
#my $return = create_page( $rvars );
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{"translations"}, $munge)->touchpath;
my $return2 = $save_file->spew_utf8($return1);
say "return2 is $return2";
system("gedit $save_file &");
sub write_monk_tags {
use warnings;
use 5.011;
use Text::Template;
use Encode;
use utf8;
binmode STDOUT, ":utf8";
use open OUT => ':encoding(UTF-8)', ':std';
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\"}: $vars{\"chapter\"}.\n";
my @buchstaben = qw/i p c readmore b/;
for my $i (@buchstaben ) {
$vars{"symbol"} = $i;
print "How many $i tag pairs would you like?: ";
my $prompt = <STDIN>;
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__
$
The output doesn't show on perlmonks. It does in the file that is formed from the munged time. This becomes the prep file for the write-up. Tags are arrayed in order, with nothing between open and close tags, so that's hardly surprising. I wanted to write this utility before I did anything more, to turn my character defect of laziness into something keystroke-saving in the long haul.
The source file for Text::Template object is:
$ cat 1.monk.tmpl
<{$symbol}></{$symbol}>
$
I realize that there are much smaller ways to do what I have achieved here and would solicit them. I believe that Path::Tiny will create the directories it needs with the touch method. My pride will not be hurt to see this shortened by great lengths. This isn't going to be the only thing I use Text::Template for in the near term, so I wanted to roll it out with the full framework of Path::Tiny.
Namaste,