I am basically a networking guy and so not good at writing scripts.
While writing some scripts I came across below requirement.
I have a hash array with some values of "1" or "2" and my requirement
if all of the value equal to other than "1" (could be "2" or "3") then it will print some statement once and then come out of that loop.
if any of the value equal to "1" then it will print some statement.
ex:
my %hash_array1=(A=>2,B=>2,C=>2);
my @array2=values (%hash_array1);
foreach my $line (@array2) {
if ($line!=1) {
print BOLD GREEN "\rNo Evolution ",RESET;
last;
}
else {
print BOLD RED "Evolution \n",RESET;
}
}
which print
No Evolution
Above code work well as expected for mentioned hash_array because all values are non-"1",but not working well for below hashes
my %hash_array1=(A=>1,B=>2,C=>2);
where it prints
Evolution
No Evolution
which is not as per my expectation. I want here to print as one time "Evolution" and "No Evolution" should not be printed any more. (However loop should be continued to iterate)
Please let me know if more clarity is required.
Regards
Mahesh
I would use something like: