Ah, I feel your pain: I recently had to paginate results from SQL Server, and wasn't allowed to modify the SQL in any way (stupid over-defensive stored proc devs...). Here's the basic idea of the solution I came up with.

# a unique SessionID for the query already available # in package global $session my $cache_file = $session.'_cache.yaml'; my $result_set; if (-f $cache_file && -r $cache_file && -s $cache_file) { # we already ran this query (session), and we have a cache! $result_set = YAML::LoadFile($cache_file); } else { $result_set->{data} = run_dbQuery(); $result_set->{start} = 0; } display_results( $result_set->{data}, $result_set->{start}, 20 ); $result_set->{start} += 20; YAML::DumpFile($cache_file, $result_set); #---- display_results : shows slice of result set ---- sub display_results { my ( $data, $start, $length ) = @_; die "Data Set is not an ARRAY ref" unless ref $data eq 'ARRAY'; my $endpoint = ( $start+$length > @$data ? @$data-1 : $start+$lengt +h-1 ); show_toBrowser( @$data[$start..$endpoint] ); }

Essentially, I cache the full result set in a YAML file. When I need the next page, I restore the array in the YAML file and just use an array slice to get the subset I want. This might be a bad idea for huge data sets, but it should get you thinking in the right direction (assuming you can't use SQL Server to do the pagination for you, which will likely be much faster).

I deal with cache expiration and removal in session restoration and destruction calls elsewhere.

<radiant.matrix>
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re: SQL Paging with Perl by radiantmatrix
in thread SQL Paging with Perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.