Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
There can be a large number of matches, so I wanted to write something like when you do "ls | more" and you get the output in chunks of 20 or so, hitting enter for the next chunk.
My code is a bit of a hack, with "if $x < $#list && $x+20 >= $#list"-type code everywhere. Please don't make me show it to you. It works anyway.
My question is more of a golf one, "what's the best way to work through an array over 20 items long in chunks of 20?"
I was trying to do something like this:
But that doesn't work for various reasons which I'm sure are obvious to most monks (stop laughing!).while(@array){ print @array[0 .. 20]; delete @array[0 .. 20]; }
So, without the use of termporary vars to progressively get 0 .. 19, then 20 .. 29 and so on, how would you do it?
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Working Through An Array In Chunks
by blokhead (Monsignor) on Dec 06, 2004 at 03:17 UTC | |
by Cody Pendant (Prior) on Dec 06, 2004 at 22:43 UTC | |
by Zed_Lopez (Chaplain) on Dec 07, 2004 at 01:42 UTC | |
by Cody Pendant (Prior) on Dec 07, 2004 at 02:36 UTC | |
|
Re: Working Through An Array In Chunks
by Roy Johnson (Monsignor) on Dec 06, 2004 at 03:18 UTC | |
|
Re: Working Through An Array In Chunks
by BrowserUk (Patriarch) on Dec 06, 2004 at 03:50 UTC | |
|
Re: Working Through An Array In Chunks
by davido (Cardinal) on Dec 06, 2004 at 05:28 UTC | |
|
Re: Working Through An Array In Chunks
by revdiablo (Prior) on Dec 06, 2004 at 21:13 UTC |