Paul Archer wrote: > Is there any (quick and easy) way to get a reverse range, > like (10..1), > rather than a standard (1..10)? The catch is to *not* use 'reverse'. > I'm teaching Sun's perl course this week (DTP-250), and we > were talking > about working on arrays. The book had an exercise that had the student > reverse an array by using pop (or shift, I don't remember). > That section is > before we talk about 'reverse', and I thought you'd be able > to do it like: > @array[0 .. $#array] = @array[$#array .. 0] > ...but of course, having the range count down doesn't work.
This works: @arr = map pop(@arr), @arr; but seems overly tricky, IMO. The far more straightforward: @arr = reverse @arr; would be preferred. If you're teaching a class, I think you want to avoid using trickery just to steer clear of a concept you haven't introduced yet. I would either go ahead and introduce reverse(), if your purpose is to reverse an array. Or, I would stay away from reversing arrays if your purpose is to illustrate the range opeator. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]