Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
can somebody give me some pointers as to how I do the following
I have a piece of code that consists of two loops
This produces an output filewhile(<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"; } } }
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 beANY: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
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:spicejam:07F7817D470004327B471FC5327B050F:NONBKID ANY:henders:07F7817D470004327B:nbhoijk ANY:riffty:07F7817D470:nbaz94k ANY:johbe:07F7817D470004327B471FC5327B050FE04379:NONBKID .... etc
Any help would be appreciated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: One loop or two
by locked_user sundialsvc4 (Abbot) on Aug 01, 2012 at 13:40 UTC | |
by Anonymous Monk on Aug 01, 2012 at 14:49 UTC | |
|
Re: One loop or two
by jayto (Acolyte) on Aug 01, 2012 at 13:40 UTC | |
|
Re: One loop or two
by BillKSmith (Monsignor) on Aug 01, 2012 at 15:54 UTC |