in reply to how to choose the greater or equal number in array

Hello lakshu and welcome to the monastery and to the wonderfull world of Perl!

1nickt gave you a good answer using a core module. It is always good to know them and using them at your and their best.

It is also good to know the function you use: push is used in the wrong way in you sub. Infact push Returns the number of elements in the array following the completed push so at the first iteration you return 1 from the sub and all end.

You are using my @test_array = (3,6,,7,6,3,10,5,6,2, 10); (declaring my (@test_array); in a separate line is inutil..) and you pass it to your sub.

Let's follow what happens:

The array enter the sub as @_ and you assign the whole to it: my @numbers = @_; it's enough. then you initializze some empty vars: my ($min, $max, @ret1); here parens are needed. after you set $min and $max with the value of 3, the first numer entering the sub.

At the first iteration of the foreach loop $i is 3 so if ($i >= $max) is true because $max is still 3 so the block is executed: return push my(@ret1), $i; immediately ends the sub returning the final number of elements present in @ret1 after pushing 3 to it. ie 1 element. No other numbers are processed.

Translated in english it goes like: given a num list, when a number is greater or equal to the first, put it on a list and return how many items the ending list contains. Obviously this is true every time for the first number you pass.

Remeber that print is your friend and is the first powerfull debugging tool you have

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.