#!/usr/bin/perl -w use Carp; use strict; use warnings; my $template_name = 'C:\Perl\template\template1.html'; my $db_name = 'C:\Perl\template\text1.txt'; my $index = 'filename.ext'; my $start_dir = 'C:\Perl\template\website'; my @star_dir = split (/\\/, $start_dir); foreach (@star_dir) { if ($_ eq 'C:') {$_ = 'C:\\'} unless (-e "$_") { mkdir ("$_", 0700) or die "can't mkdir $_: $!"} chdir ("$_") or die "can't chdir $_: $!"; } my $i = 0; my $k = 0; open (DB, "<$db_name") or die "can't open $db_name: $!"; PRINTING_LOOP: local $/ = "****$index****"; while (<DB>) { if ($i == 0) { $i = 1; next; } else { chomp; if ($index eq 'filename.ext') { my @dir = split (/\\/); foreach (@dir) { if ($_ eq "$dir[-1]") { open (NEWFILE, ">$_") or die "can't open $_: $!"; foreach (@dir) { if ($_ eq "$dir[-1]") {last} else {chdir ("..") or die "can't chdir ..: $!" +} } } else { unless (-e "$_") {mkdir ("$_", 0700) or die "can't + mkdir $_: $!"} chdir ("$_") or die "can't chdir $_: $!"; } } open (TEMPLATE, "<$template_name") or die "can't open $tem +plate_name: $!"; } else { print NEWFILE "$_"; if ($k == 1) { $index = 'filename.ext'; $k = 0; $i = 0; goto PRINTING_LOOP; } } local $/ = "****"; my $j = 0; while (<TEMPLATE>) { chomp; if (eof(TEMPLATE)) { if ($j == 0){ print NEWFILE "$_"; close (NEWFILE); close (TEMPLATE); $i = 0; $index = 'filename.ext'; goto PRINTING_LOOP; } else { $index = "$_"; close (TEMPLATE); $i = 0; $k = 1; goto PRINTING_LOOP; } } else { if ($j == 0) { print NEWFILE "$_"; $j = 1; } else { $i = 0; $index = "$_"; goto PRINTING_LOOP; } } } } } close (DB);

In reply to efficient template by maddfisherman

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.