Can I make a template from a garden variety lexical variable?

When I'm silent on threads where I've asked questions, it is usually time where I hit the reading that responders post and try out all the elbow grease I can muster, as I make keystrokes writing scripts that are imperfect. Occasionally, I get a couple good ones to post, and I think this falls into that category.

Text::Template is too big a hammer for this nail. Native perl is enough.

my $tag_pair = '<x></x>'; new_string =~ s/x/${letter}/g;

The system call at the end of this is for windows. I intend to ask the perl hive mind how to make a grown-ups' switch control to probe for what OS the script is being run on, but not here, as the premise that I was on a windows machine was in the original post. Furthermore, I'm 5 deep in terms of the response levels, and I don't want to start anything new. It's impossible to show the output without running a script on it to substitute out special characters, the ones you always need in better writeups. We want to end up with a real file, so we can make that the basis of showing code and discussing it in terms of other sources on pm and the internet. Better writeups reference others, IMO. I guess what I can show for output is the ultimate file created by Path::Tiny:

created file C:/Users/tblaz/Documents/evelyn/perlmonks/writeups/21-08-2019-10-33-27.monk.txt

Source:

#!/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 = "perlmonks"; my $output = "writeups"; ## 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 = <STDIN>; chomp $prompt; die unless ( $prompt eq "y" ); ## special do-hickeys I want at the end my @list = ( '[id://3989]', '[|]', '[|]', '&lt;', '&gt;', '&#91;', '&# +93;' ); @list = map { "$_\n" } @list; say "list is @list"; my $return1 = write_monk_tags(); 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( $path2, $output, $munge )->touchpath; my $return2 = $save_file->spew($return1); say "return2 is $return2"; my $return3 = $save_file->append(@list); say "return3 is $return3"; say "created file $save_file"; system( 1, 'C:\Program Files (x86)\Notepad++\notepad++.exe', $save_fil +e ); sub write_monk_tags { use warnings; use 5.011; my $tag_pair = '<x></x>'; my $return = ''; # User: change these quoted values for different order or tags my @buchstaben = qw/i p c pre readmore b/; for my $letter (@buchstaben) { print "How many $letter tag pairs would you like?: "; my $prompt = <STDIN>; chomp $prompt; while ( $prompt gt 0 ) { my $new_string = $tag_pair; $new_string =~ s/x/${letter}/g; say "new string is $new_string"; $return = $return . $new_string . "\n"; --$prompt; } } return $return; } __END__

Of course, I'll consider any criticism of this. Thx pryrt for your comments to get me moving on this new machine.


In reply to Re^5: getting a few simple scripts to work on windows by Aldebaran
in thread getting a few simple scripts to work on windows by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.