Take the 2-minute tour ×

I've spent ~6 hours trying to figure this out. I'm hoping a perl guru will help.

I have a program that loops, updating a hash with information about servers I'm polling. I'm using HTTP::Server::Simple::CGI to report this information to users. I am running into an issue where the HTTP::Server::Simple::CGI module will not see updates to the hash and will only report data that the hash was initialized with.

I have the following code, abridged:

package LabBrowser;

use warnings;
use strict;
use Thread::Queue;
use LWP::Simple; 
use HTTP::Server::Simple::CGI;

my %problem_data_structure;

sub server_loop {
    while(1) {
        for my $server (@server_list) {

sub fetch_server_info {
    my ($hostname, $port) = @_; 
    my $content = fetch_webpage_content("http://" . $hostname . ":" . $port);   
    my @data = parse_data(content);
    $problem_data_structure{$hostname} = [@data];

sub handle_request {
    my ($self, $cgi) = @_;
    my $path = $cgi->path_info();

    ##THIS LINE 
    print Data::Dumper->Dump([\%problem_data_structure],['handle']);



my $pid = LabBrowser->new(8080)->background();
my $labBrowser = LabBrowser->init();
print "$pid !!!\n";

I can get the data in %problem_data_structure anywhere in the program, except for handle_request. There, it seems as if it only knows about what the variable was initialized to. If I add some key, value pairs in the beginning, it will report that. However, it will not report anything added to the data structure since initialization.

Does anyone know what's going on?

share|improve this question
could you show us the code as to how you'r calling handle_request –  keety May 10 '12 at 0:54

1 Answer 1

up vote 1 down vote accepted

The background() is a clue that requests are being handled in a background process. Processes in Perl do not share memory, so when %problem_data_structure is modified in handle_request, the (original) copy of %problem_data_structure in the parent process is not affected.

share|improve this answer
Great Scott! That's it! I love you. I didn't consider that there would be another process, even though the documentation does state that there would be. Bleh! Can I buy you a beer via paypal? –  kheck May 10 '12 at 1:50

Your Answer


