in reply to search HoA-reference
I quickly re-wrote the logic in the sub to iterate over the user-args in the outer loop, then do the loop over the structure on the inner loop. This makes it a bit easier to achieve what I believe you want.
First, I removed the re-assignment of the parameters to avoid unnecessary overhead, and just use the aref directly in the code. Other than the restructuring, I've also changed from iterating over the inner array within the hash to just using grep instead. Note I've also added a $found flag. This is how we track whether the WWN has been found or not within the entire structure. This variable gets reset each time we look for a new user-supplied WWN.
The code assumes that only a single WWN can be found in the entire structure. If it can be in numerous places (which I can't see how and would indicate larger issues I would think), then change the last to a next inside the grep condition.
sub _compare_match_WWPN { die "no parameter!\n" unless @_; my ($w_ref) = @_; for my $name (@{ $w_ref }){ my $found; for my $rmtkey (sort keys %wwns){ if (grep {$name eq $_} @{ $wwns{$rmtkey} }){ print "Found '${name}' that belongs to $rmtkey\n"; $found = 1; last; } } if (! $found){ print "$name not found!\n"; } } return; }
Output:
Enter your wwns to search for? More than one, comma seperated: ---> 20 +09000g123456ff,500143802483cfe5 2009000g123456ff not found! Found '500143802483cfe5' that belongs to rmt42
|
|---|