Hi

can somebody give me some pointers as to how I do the following

I have a piece of code that consists of two loops

while(<FILE1>) { chomp; my @fields = split(/:/, $_); my $result = qx{ /opt/bin/target -e$fields[2] }; print FILE2 "$fields[0]:$fields[1]:$result:NONBKID\n"; foreach my $configParameter (keys %{$configHash}) { my $nbkid = $configHash->{$configParameter}{'nbkid'}; my $ntid = $configHash->{$configParameter}{'ntid'}; if ($ntid eq $fields[1]) { print FILE2 "$fields[0]:$fields[1]:$result:$nbkid\n"; } } }
This produces an output file
ANY:spicejam:07F7817D470004327B471FC5327B050F:nbkufdc ANY:spicejam:07F7817D470004327B471FC5327B050F:NONBKID ANY:henders:07F7817D470004327B:nbhoijk ANY:henders:07F7817D470004327B:NONBKID ANY:riffty:07F7817D470:nbaz94k ANY:riffty:07F7817D470:NONBKID ANY:johbe:07F7817D470004327B471FC5327B050FE04379:n3456hk ANY:johbe:07F7817D470004327B471FC5327B050FE04379:NONBKID .... etc
What I wanted it to do was to either print the line with NONBKID in it or the line that matched the string compare but not both. e.g. The output should be
ANY:spicejam:07F7817D470004327B471FC5327B050F:NONBKID ANY:henders:07F7817D470004327B:nbhoijk ANY:riffty:07F7817D470:nbaz94k ANY:johbe:07F7817D470004327B471FC5327B050FE04379:NONBKID .... etc
I'm not sure how to achieve this. The outside loop iterates through each record and then the inside loop also iterates through potentially hundreds of records looking for a match with the outside loop record. So I need a match in the inside loop to overwite the print from the outside loop if a match exists.

Any help would be appreciated


In reply to One loop or two by Anonymous Monk

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.