We don't bite newbies here... much | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I already posted an example of another way to do this subroutine at Re: Trudging along the learning perl path..
Below, I have modified your code which uses array indices and "looks forward" to the next element. I am sure you wondered why you needed to sort the array yet again? That is because the index of -1 means the last element of the array in Perl and that caused the largest value to appear at the beginning of the @unique array. Here is another way of using "look ahead" indicies.... compare with your code... I encourage you to sign up for a Perl Monk logon. You are trying to learn and are writing code. Beginners don't write perfect code and by the way sometimes experts don't either! Update: There is a problem with the above code if say, there is only a single element in @arr, i.e., @arr=(29);. This is one of several reasons why I would discourage iterating over array indices in Perl code. In reply to Re: Trudging along the learning perl path.
by Marshall
|
|