in reply to hash keys, %
Even if this isn't quite what you had in mind, maybe the while( .. splice .. ) loop will be a good starting place. The loop condition won't fail until @group gets 0 items, and will still iterate even if @group gets less than 20 the last time through the loop.my @keys = sort keys %hash; my $group = 0; while (my @group = splice(@keys, 0, 20)) { ## generate url from stuff in @group $group++; ## maybe something like this if the items ## are all safe (\w characters): my $url = 'script.cgi?' . join '&', map { "x=$_" } @group; print qq(<a href="$url">group # $group</a><br>\n); }
Update: if the links only depend on the number of keys, and not the keys themselves, then the number of URLs to print is simply ceil( (keys %hash) / 20 ). ceil simply rounds up, you can import it from the POSIX module.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: hash keys, %
by sulfericacid (Deacon) on Jul 29, 2003 at 01:02 UTC | |
by blokhead (Monsignor) on Jul 29, 2003 at 01:30 UTC |