c has asked for the wisdom of the Perl Monks concerning the following question:
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 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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: processing a file once within a nest for loop
by ferrency (Deacon) on Feb 15, 2002 at 14:55 UTC | |
Re: processing a file once within a nest for loop
by Speedy (Monk) on Feb 15, 2002 at 23:03 UTC |
Back to
Seekers of Perl Wisdom