How would one accomplish the following using Text::Template?

I am trying to confirm syntax on a particular config file. The code below populates the template, using values from the last iteration through %vars.

Thanks again, Steve

#!/usr/bin/perl -w use strict; use Text::Template; my %vars; my $lines; while ($lines = <DATA>) { next if ($lines =~ /^\#/); if ($lines =~ /(\d+)(\s+)map(\s+)(\w+)\:\/\/(.*?)(\4)\:\/\/(.*$)/){ $vars{'proto'} = $4; $vars{'uri1'} = $5; $vars{'uri2'} = $7; } } my $result = $template->fill_in(HASH => \%vars); if (defined $result) { print $result } else { die "Couldn't fill in template: $Text::Template::ERROR" } __DATA__ 1 map http://www.digitalcity.com http://origin-www.digitalcity.com 2 map tunnel://www.digitalcity.com tunnel://origin-www.digitalcity.com 3 map http://10.0.2.1 http://origin-www.digitalcity.com 4 map tunnel://10.0.2.1 tunnel://origin-www.digitalcity.com 5 reverse_map http://origin-www.digitalcity.com http://www.digitalcity +.com 6 reverse_map tunnel://origin-www.digitalcity.com tunnel://www.digital +city.com ========================================== TEMPLATE: {$d} map {$proto}://{$uri1} {$proto}://{$uri2} {$d} map {$proto}://{$uri1} {$proto}://{$uri2} {$d} map {$proto}://{$uri1} {$proto}://{$uri2} {$d} map {$proto}://{$uri1} {$proto}://{$uri2} {$d} reverse_map {$proto}://{$uri2}://{$proto}://{$uri1} {$d} reverse_map {$proto}://{$uri2} {$proto}://{$uri1}

In reply to Text::Template iteration problem by Tuna

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.