Thank you.

The skel tool is written in C and, on top of the simple core idea, it offers a lot of small additional features, like lowercase/uppercase conversion and support for default values. My script could hardly be considered an improvement over the original - but it could complement it, when you need just the core functionality and the one feature I've added.

I could try to port this feature to the original, as I would be happy to contribute to a tool I use, but I'm not sure if my C skills are up to it. But I will still fork it and try, if time allows.

Just for completeness sake, here is my initial version with just the core functionality:

#!/usr/bin/perl use v5.14; my %cfg = ( tmpl_path => $ENV{HOME}.'/.skel-closet/', opening_tag => '#{', closing_tag => '}', ); sub filled_line { my $line = shift; my $pattern = qr/$cfg{opening_tag}(.+?)$cfg{closing_tag}/; $line =~ s/$pattern/$ENV{$1}/g; return $line; } my $filename = $cfg{tmpl_path}.shift; open (my $fh, '<', $filename) or die ("Could not open file: $filename"); print filled_line($_) while (<$fh>); close ($fh);

Not much use for it over the version I posted earlier, but it shows the one thing that still bugs me. The sub is called filled_line, because I knew I wanted a nice sounding noun for the print filled_line expression. With the switch to buffering in the second version, this nice sound of the penultimate line was unfortunately lost - I could not push filled_line($_) to @output, because push does not work that way.

Someone might say that this is completely irrelevant, but the way I see it, if I did not care about the way those lines sound, I would not be so attached to Perl.

- Luke


In reply to Re^2: Minimal, %ENV based templating tool by blindluke
in thread Minimal, %ENV based templating tool by blindluke

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.