Hello Monks, I seek your divine wisdom in solving or helping me solve a problem with keeping data persistant while using Net::Daemon in fork mode. When I run the script in single mode the stored data remains between sessions but when I run the script using fork mode the stored data is lost with each new session. What do I need to do to be able to retain the data while running in fork mode ?

Hope I made some sense.. Thanks !!
#/usr/bin/perl use strict; use test_demon; require Net::Daemon; my(%PERSISTANT_HASH); my $server = test_demon->new( { 'pidfile' => 'test_demon.pid', 'logfile' => 'test_demon.log', 'localport' => 81, 'mode' => 'fork'}, \@ARGV); $server->Bind(); package test_demon; use strict; use vars qw($VERSION @ISA); @ISA = qw(Net::Daemon); sub Run ($) { my($self) = @_; my($line, $sock); $sock = $self->{'socket'}; while (1) { if (!defined($line = $sock->getline())) { if ($sock->error()) { $self->Error("Client error %s",$sock->error() ); }; $sock->close(); return; }; $line=~s/\r|\n//gi; my ($command,$key,$value) = split(/ /,$line,3); $command = lc($command); if ($command eq "set") { $::PERSISTANT_HASH{$key} = $value; }; if ($command eq "bye") { $sock->close(); return; } else { print $sock $::PERSISTANT_HASH{$key} . "\n"; }; }; $sock->close(); }; 1;

In reply to Persistant data using Net::Daemon in fork mode 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.