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 => '&#1084;&#1086;&#1085;&#1072;&#1093; &#1090;&#1077;& +#1075;&#1080;', server_dir => 'perlmonks', image_dir => 'pmimage', ); my $variable = "&#1087;&#1077;&#1088;&#1077;&#1084;&#1077;&#1085;&#108 +5;&#1072;&#1103;"; say "variable is $variable"; my $&#1087;&#1077;&#1088;&#1077;&#1084;&#1077;&#1085;&#1085;&#1072;&#1 +103; = "variable"; say "&#1087;&#1077;&#1088;&#1077;&#1084;&#1077;&#1085;&#1085;&#1072;&# +1103; is $&#1087;&#1077;&#1088;&#1077;&#1084;&#1077;&#1085;&#1085;&#1 +072;&#1103;"; 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.


Replies are listed 'Best First'.
Re: monk tags
by Aldebaran (Chaplain) on Nov 27, 2018 at 21:58 UTC

    This version is better, free of unused libraries and unneeded sources you don't have, and russian to get shredded by the code tags. One can make the code tags with fewer keystrokes, but we need to have our write-up capability close to where it's happening. Path::Tiny is great for figuring out where it is and then being able to create files and directories on the fly.

    This version has the tags without intervening newlines, which was at first was a bug I tried to fix until I realized I could just as well call it a feature. As it is the caret of my typing moves all the tags toward the end of file.

    Then Enter after the closing tag for each paragraph or code segment to maintain legibility for oneself. The readmores are at the end, because you drape that over particulars so that only the willing will have to use their scroll fingers. What follows is new output and then source:

    Now I have to go deal with world of concrete, uggh....