in reply to Pipe Complex Data Structure
I apologize, I did not realize the code was essential to solving the problem. The following is a sample code because the original code is much too long to list:
# First we must create our data structure. $master_matrix->[0]->{'animal'} = "tiger"; $master_matrix->[0]->{'size'} = "big"; $master_matrix->[0]->{'speed'} = "fast"; $master_matrix->[1]->{'animal'} = "bear"; $master_matrix->[1]->{'size'} = "bigger"; $master_matrix->[1]->{'speed'} = "medium"; $master_matrix->[2]->{'animal'} = "sobes"; $master_matrix->[2]->{'size'} = "tiny"; $master_matrix->[2]->{'speed'} = "quick"; $master_array = [5, 7, 9, 12, 4]; # Now we can do the parallel processing. use IO::Handle; use Data::Dump; $max_core = 1; foreach $core_number (1..$max_core) { pipe ($reader, $writer); $writer->IO::Handle::autoflush(1); $pid = fork(); if ($pid) { # This is the parent process close $writer; undef $master_matrix; undef $master_array; $child_process_numbers{$core_number} = $pid; $child_file_handles{$core_number} = $reader; undef $reader; } elsif ($pid == 0) { # This is the child process close $reader; print "child master matrix: $#{$master_matrix}\n"; $frozen_data = Data::Dump->pp($master_matrix); print $writer $frozen_data; close $writer; exit(0); } else { # Process is undefined die "couldn't fork: $!\n"; }; }; foreach $core_number (keys %child_process_numbers) { $pid = $child_process_numbers{$core_number}; $reader = $child_file_handles{$core_number}; $frozen_data = <$reader>; undef $reader; $thawed_data = eval($frozen_data); print "thawed data: $#{$thawed_data}\n"; waitpid($pid, 0); }; exit;
I have decided to use Data::Dump because of the Storable "version" problem (discussed on your website and several others). The code is set up to generate multiple children, but I have it set to only generate one for simplicity. The code is able to produce the correct answer if I use the $master_array, but it does not produce the correct answer if I use the $master_matrix (an array of hashes). Hopefully this will help everyone.
Thank you Monks for all of your help.
Scott
|
|---|