Hello Monks,

I am working on a program that forks 3 childern. The first child acts as a perent to the next two.

Job for the first Child:

- Update a Variable called dirListing.

- Checks filesDownloaded array and takes action based on filename.

Job for two childern:

- Check dirListing array content and take action based on the filename.

- If action is taken then added filename to filesDownloaded array.

when I run the program I keep getting the following error.

Can't use an undefined value as an ARRAY reference at /shmem/lib/lib/perl5/site_perl//5.8.5/IPC/Shareable.pm line 446. IPC::Shareable::FETCHSIZE('IPC::Shareable=HASH(0x79baf0)') called at ./test_nfxftpd line 63

Please help, I have watsed so much time with this, Thanks in advance.

#! /usr/bin/perl -w use strict; use lib "/nss/nfx/shmem/lib/lib"; use lib "/nss/nfx/shmem/lib/lib64"; use lib "/nss/nfx/shmem/lib/lib/perl5/site_perl/"; use File::Basename; use Getopt::Long; use File::Copy; use strict; #use IPC::Shareable; use IPC::Shareable qw(); my $child; my $serv_id; my $maxRcvrCount; my $stripeInstance; my $maxStripeInstance; my $user; my @ftpDirectoryListing=(); my @dirListing=(); my @filesDownloaded=(); my $glue = 'data'; my %options = ( create => 1, exclusive => 0, mode => 0644, destroy => 1, ); my $dirListingHandle = tie @dirListing, 'IPC::Shareable', 'data', \%op +tions; my $filesDownloadedHandle = tie @filesDownloaded, 'IPC::Shareable', 'k +ala', \%options; sub pollDaemonParent { my $user = $_[0]; my @previousListing=(); my @currentListing=(); while (1) { @previousListing = @currentListing; @currentListing = getListing($user); $dirListingHandle->shlock(); @dirListing = deDupArray1(\@previousListing, \@currentListing) +; print "Parent: currentListing: @currentListing dirListing: +@dirListing\n"; $dirListingHandle->shunlock(); deleteRemoteFiles1(); select (undef, undef, undef,.5); } } sub deleteRemoteFiles1 { # TODO: Get list and delete from server. once deleted $filesDownloadedHandle->shlock(); if ($#filesDownloaded >= 0) { print "\nParent: deleteListing: @filesDownloaded\n"; } foreach (@filesDownloaded) { deleteFile($_); } @filesDownloaded=(); $filesDownloadedHandle->shunlock(); } sub pollDaemonChild { my $user = $_[0]; print "ChildStarted: $stripeInstance\n"; while (1) { @ftpDirectoryListing = (); $dirListingHandle->shlock(); @ftpDirectoryListing = @dirListing; $dirListingHandle->shunlock(); if ($#ftpDirectoryListing >= 0) { print "Child - @ftpDirectoryListing: @ftpDirectoryListing\ +n"; } select (undef, undef, undef,1); } } sub getListing { my @ftpListing1 = (); push (@ftpListing1, "abc.xml"); push (@ftpListing1, "xyz.xml"); return @ftpListing1; } sub deDupArray1 { my @difference = ("dedup1.xml", "dedup2.xml"); return @difference; } sub addToDeleteList { $|++; $filesDownloadedHandle->shlock(); push (@filesDownloaded, "$_[0]"); $filesDownloadedHandle->shunlock(); } # main { $user = "IAmUser"; $serv_id = "1"; $maxRcvrCount = "5"; $stripeInstance = "1" ; $maxStripeInstance = "3"; $SIG{'ALRM'} = 'sig_alrm'; my $startingInstanceNum=1; my @kids; for (1 .. $maxStripeInstance) { $stripeInstance = $startingInstanceNum; print "stripeInstance: $startingInstanceNum\n"; unless ($child = fork) { # i'm the child die "cannot fork: $!" unless defined $child; if($stripeInstance == 1 ) { pollDaemonParent($user); } else { pollDaemonChild($user); } exit; } push @kids, $child; # in case we care about their pids $startingInstanceNum++; } while (1) { sleep 1; } }

In reply to Shared Memory using IPC::Shareable - Can't use an undefined value as an ARRAY reference by mr_p

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.