Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I need to execute "else" condition only if , foreach checks all the values of the array and array has become empty. I am using the following code (some commands are internal to the organization, but you can infer)
$rh->cmd('show pim join summary | except "^Instan +ce|^Route"'); my $output = $rh->get_response; my @outputlist = split /\s+/, $output; foreach $output (@outputlist) { if ($output eq "3000") { put_log("All PIM groups are learned in + Master"); } else { put_log ("fail"); } }
output of the above command "show pim join summary | except "^Instance|^Route" is below
regress@sherlock# run show pim join summary | except "^Instance|^Route +" (s,g) 3000 200
In the above code, foreach gets each member of the array and it finds 3000 in the middle and it passes, but i want the else condition to be executed only once , not for each array element comparison. More precisely, else should be excuted only after the array is empty and 3000 is not found. Is there a way to do it
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Set condition only if array becomes empty
by choroba (Cardinal) on Sep 26, 2017 at 12:57 UTC | |
|
Re: Set condition only if array becomes empty
by thanos1983 (Parson) on Sep 26, 2017 at 13:04 UTC | |
by 2teez (Vicar) on Sep 26, 2017 at 20:25 UTC | |
by Laurent_R (Canon) on Sep 26, 2017 at 21:17 UTC | |
| |
|
Re: Set condition only if array becomes empty
by virtualsue (Vicar) on Sep 27, 2017 at 09:23 UTC |