The above map operation will check any element of the array and store it to temp if it is greater than 10. Finally,we will check whether the temp is containing value or not.If it isn't undef,printing the message as greater than 10 in an array. If you don't want to store any temporary variable,then you try this.use strict; use warnings; my @array=(34,52,67,3,66); my $temp; map { $temp=$_ if $_ > 10 } @array; print "Yes,at least one number is bigger than 10\n" if($temp);
use strict; use warnings; my @array=(34,52,67,3,66); map { print "Yes,at least one number is bigger than 10\n" and exit if +$_ > 10 } @array;
In reply to Re: Check if at least one element of array is bigger than X
by nvivek
in thread Check if at least one element of array is bigger than X
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |