i ran into an interesting problem this morning that i was able to fix, but leaves me thinking that the script does a little more processing than it should/i want it to.
my code:

my @subs = qw(itchy.foo scratchy.bar homer.bab); open(FH, "template") or die; my @tmpl = <FH>; close(FH); for my $i(@subs) { open(FH,">virt.$i") or die; for my $j(@templ) { $j =~ s/^(\w+)\@DOMAIN$/$1\@$i/; print FH $j; } close(FH) }

now, it makes sense that this works for the first value in @sub, but doesnt work for the remaining two, since each of the files opened will be written out with the first instance in the for $i loop, meaning that subsequent matches of DOMAIN won't be found. its easily remedied by matching against \w+ rather than an explicit DOMAIN, however, i end up processing more than i would like. when my @subs lists gets *very* long, that could be a bad thing. i continue to loop over it in my head, but i am not sure of the right way to do this.

thanks -c


In reply to processing a file once within a nest for loop by c

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.