One call to a module (You could use grep, but the module is more explicit) can replace the inner loop. Use of values rather than keys simplifies the syntax. The single print statement emphasizes your intent to print one line.
use strict; use warnings; use List::MoreUtils qw( first_value ); my %configHash; while(<FILE1>) { chomp; my @fields = split(/:/, $_); my $result = qx{ /opt/bin/target -e$fields[2] }; my $id = first_value {$_->{'ntid'} eq $fields[1]} values %configHash; my $source = $id ? $id->{nbkid} : 'NONBKID'; print FILE2 "$fields[0]:$fields[1]:$result:$source\n"; }
untested
In reply to Re: One loop or two
by BillKSmith
in thread One loop or two
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |