Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8681599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:33:06+00:00 2026-06-12T21:33:06+00:00

I’m using Perl to populate two html tables (each table is generated in its

  • 0

I’m using Perl to populate two html tables (each table is generated in its own Perl CGI script). I have a ‘helper’ script that runs an SQL query. Here’s an example (let’s call this script run_sql_query.pl):

my $sql_query = "SELECT ID from TABLE where ID > 3";
our $sth = $dbh->prepare($sql_query);
$sth->execute;

Then, in each of my two Perl CGI scripts, I do:

require 'run_sql_query.pl';

our $sth;
while (my ($table_id) = $sth->fetchrow_array) {
...
}

However, it looks like run_sql_query.pl is running twice (once in each of the Perl CGI scripts). How can I have it so run_sql_query.pl gets executed only once and then use the same $sth contents in both of the Perl CGI scripts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:33:08+00:00Added an answer on June 12, 2026 at 9:33 pm

    If I understand correctly, you want to save the result of a query so it can be used again by a different process. There’s several ways of doing this, all involving setting up a cache of some sort.

    CGI processes have separate memory, so you can’t do what you ask directly. Worse, they’re started and stopped for each request wasting a lot of time compiling. However, there’s lots of ways around that.

    If your SQL query is expensive, and the data does not change often, you can have the database cache the result. Here’s the MySQL cache, for example. This has the advantage that everything which uses the database will be using it. The disadvantage is your programs still have to fetch and process all the data. Use this is your query is expensive, but fetching and processing it is not, and your data does not change often.

    Another option is to set up an external cache, such as memcached, to store the results. Memcached is basically a server on your machine that stores a big hash of data. Or you can even use the database itself to cache the processed HTML table. Each process can check if the data they want is in the cache before calculating it themselves. You can use something like CHI to interface with it. The advantage is you can chuck anything you want into the cache. The disadvantages are that you have to manage the cache yourself (ie. delete data when it goes out of data), it’s another thing to manage, and the cache could disappear at any time.

    Finally, you can change how your processes are run. A basic efficiency gain is to change from plain CGI, which starts, compiles, runs and finishes your program for every request, to something like FastCGI which runs your program in its own little server. Think of it like putting a while loop around your whole program. Now since your program isn’t shutting down between each request, you can store data in global variables. Then its a simple matter to do what @foampile suggested, store your table in our @Table_Cache or the like. This will cache it for that process but not for others. Each different program is its own process. So foo.cgi won’t share with bar.cgi. The advantages are its easy, FastCGI is something you should be switching to anyway, and your web server probably already supports it. The disadvantages are that you need to manage the cache (ie. delete outdated entries), and it doesn’t share across processes.

    I’d start with FastCGI and see if that fixes your performance problems. It means you’ll be running each query only twice per server restart instead of at every request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.