Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Using Tie with arrays on IPC::Shareable

by mr_p (Scribe)
on Oct 06, 2009 at 20:49 UTC ( [id://799589]=perlquestion: print w/replies, xml ) Need Help??

mr_p has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

Here is the code that is giving me problems.

The problem is @ftpDirectoryListing and @deDuppedArray both become arrays with Interger values and If I change them to 'undef' then I get the above error.

This is the error I get if I change it to undef: Can't use an undefined value as an ARRAY reference at /nss/nfx/shmem/lib/lib/perl5/site_perl//5.8.5/IPC/Shareable.pm line 446.

Below is the Code Output:

#! /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 Data::Dumper; use strict; ###################### ######## Shared Memory Decl. ######### use IPC::Shareable; ################ my $child; my $serv_id; my $maxRcvrCount; my $stripeInstance; my $maxStripeInstance; my $user; my @ftpDirectoryListing=(); my @deDuppedArray=(); my @filesDownloaded=(); my $glue = 'data'; my %options = ( create => 1, exclusive => 0, mode => 0644, destroy => 0, ); my $deDuppedArrayHandle = tie @deDuppedArray, 'IPC::Shareable', undef, + \%options; my $filesDownloadedHandle = tie @filesDownloaded, 'IPC::Shareable', un +def, \%options; sub pollDaemonParent { my $error = ""; my $user = $_[0]; my $tmpIntervalHolder = .5; my @previousListing=(); my @currentListing=(); ConnectAndLogin(); while (1) { @previousListing = @currentListing; @currentListing = getListing($user); $deDuppedArrayHandle->shlock(); @deDuppedArray = deDupArray1(\@previousListing, \@currentListi +ng); if ($#deDuppedArray >= 0) { print "\nParent: currentListing: @currentListing deDupp +edArray: @deDuppedArray\n"; } $deDuppedArrayHandle->shunlock(); deleteRemoteFiles1(); select (undef, undef, undef,$tmpIntervalHolder); } } sub deleteRemoteFiles1 { # TODO: Get list and delete from server. once deleted $filesDownloadedHandle->shlock(); if ($#filesDownloaded >= 0) { print "\nParent: deleteListing: @filesDownloaded\n"; } foreach (@filesDownloaded) { print "Deleting File: $_\n"; } @filesDownloaded=(); $filesDownloadedHandle->shunlock(); } sub pollDaemonChild { my $error = ""; my $user = $_[0]; my $tmpIntervalHolder = 1; print "ChildStarted: $stripeInstance\n"; while (1) { @ftpDirectoryListing = (); $deDuppedArrayHandle->shlock(); @ftpDirectoryListing = @deDuppedArray; $deDuppedArrayHandle->shunlock(); if ($#ftpDirectoryListing >= 0) { print "Child: @ftpDirectoryListing\n"; } select (undef, undef, undef,$tmpIntervalHolder); processList($user); } } sub ConnectAndLogin { return; } sub getListing { my @ftpListing1 = (); push (@ftpListing1, "abc.xml"); push (@ftpListing1, "xyz.xml"); return @ftpListing1; } sub deDupArray1 { my ($previousArray, $currentArray) = @_; my @union;my @intersection;my@difference; @union = @intersection = @difference = (); my %count = (); my $element=""; ################################################################## +################################### # get Difference of two arrays. ################################################################## +################################### # go into foreach loop for any element that exist in both previous +Array and currentArray and increment # count of element value. foreach $element (@$previousArray, @$currentArray) { $count{$element}++ } foreach $element (keys %count) { #print "$element:$count{$element}\n"; push @union, $element; push @{ $count{$element} > 1 ? \@intersection : \@difference } +, $element; } ################################################################## +################################### # Remove any element that existed in previous list from not in cur +rent list. ################################################################## +################################### my @elements_needs_to_be_removed = (@intersection, @$previousArray +); %count = (); foreach $element (@elements_needs_to_be_removed, @difference) { $count{$element}++ } @difference=(); foreach $element (keys %count) { # print "$element:$count{$element} "; push @union, $element; push @{ $count{$element} > 1 ? \@intersection : \@difference } +, $element; } return @difference; } sub addToDeleteList { $|++; #print "\nAdding file to Delete List: $_[0]\n"; $filesDownloadedHandle->shlock(); push (@filesDownloaded, "$_[0]"); $filesDownloadedHandle->shunlock(); } # main { $user = "IAmUser"; $serv_id = "1"; $maxRcvrCount = "5"; $stripeInstance = "1" ; $maxStripeInstance = "2"; $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; pollDaemonChild($user); exit; } push @kids, $child; # in case we care about their pids $startingInstanceNum++; } print "@kids\n"; pollDaemonParent($user); }

Replies are listed 'Best First'.
Re: Using Tie with arrays on IPC::Shareable
by ikegami (Patriarch) on Oct 07, 2009 at 20:50 UTC

    All that code isn't necessary to demonstrate the problem.

    I have no idea what you're changing to undef. I don't even see these integers you mentioned.

Re: Using Tie with arrays on IPC::Shareable : Please Direct
by ikegami (Patriarch) on Oct 07, 2009 at 14:23 UTC

    You haven't addressed the issues I raised previously

    Update: The parent post has been completely replaced.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://799589]
Approved by Corion
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-23 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found