Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-16 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found