Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Push it real good, or don't

by pimperator (Acolyte)
on Jun 09, 2014 at 19:55 UTC ( [id://1089316] : perlquestion . print w/replies, xml ) Need Help??

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

Very confusing error. Doesn't make sense to me pls halb When I try to push a string to an array it doesn't work. Later the array is said to be empty. But I can print the string.

Someone didn't like my chants

#!/usr/bin/perl use warnings; use strict; use File::Find; use Parallel::ForkManager; my @toUnlink; #ARRAY THAT IS NAUGHTY my $maxProcs = 3; my $pm = new Parallel::ForkManager($maxProcs); foreach my $keySets (keys %chunked){ foreach ( @{$chunked{$keySets}} ){ my $pid = $pm->start and next; my $cychpTxtFile = $fileManifest{$encryptKey}.".txt"; #Im not +showing you the whole script, but this works if ( -e $cychpTxtFile ) { push @toUnlink, $cychpTxtFile; # WHY WONT YOU WORK! print $cychpTxtFile."\n"; #PRINTS TO THE SCREEN } $pm->finish; } print @toUnlink."\n"; # NADA } $pm->wait_all_children;
Here's the output
0 /Users/.../Desktop/cychip/cyto/Oligo/Oligo 2013/010613ES/010613ESA ABN +. CONTROL_(CytoScanHD_Array)_2012.cyhd.cychp.txt 0 /Users/.../Desktop/cychip/cyto/Oligo/Oligo 2013/010613ESA ABN. CONTROL +_(CytoScanHD_Array)_2012.cyhd.cychp.txt /Users/.../Desktop/cychip/cyto/Oligo/Oligo 2012/010613ESA ABN. CONTROL +_(CytoScanHD_Array)_2012.cyhd.cychp.txt /Users/.../Desktop/cychip/cyto/Oligo/Oligo 2012/milk/010613ESA ABN. CO +NTROL_(CytoScanHD_Array)_2012.cyhd.cychp.txt 0 /Users/.../Desktop/cychip/cyto/Oligo/Oligo 2012/eggs/010613ESA ABN. CO +NTROL_(CytoScanHD_Array)_2012.cyhd.cychp.txt /Users/.../Desktop/cychip/cyto/Oligo/Oligo 2012/coffe/010613ESA ABN. C +ONTROL_(CytoScanHD_Array)_2012.cyhd.cychp.txt

Replies are listed 'Best First'.
Re: Push it real good, or don't
by boftx (Deacon) on Jun 09, 2014 at 20:11 UTC

    Data saved in a child process is not visible in the parent. (Although using threads that works.)

    Update: To clarify, a forked child inherits existing data from the parent process (i.e. the $pm object.) On the other hand, when a child dies, the parent receives nothing other than a notice if the parent is looking for it. (Although it can be argued that a parent can inherit insanity from a child.)

    You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
      Ahhh I think this is the issue at hand. How do I solve it?
        Not necessarily the best answer, but one way to do it is for the child to write to a file and the parent to read it. But that is just an idea on how to do it, I am far from being an expert on these things.

        Well, the first question is this: Do you really need to run this as a forked process?

        You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
Re: Push it real good, or don't
by Corion (Patriarch) on Jun 09, 2014 at 20:06 UTC

    Obviously, Perl thinks that what is in $cychpTxtFile does not point to a valid filename.

    There are two easy ways for this to happen:

    • There is whitespace at the end of the filename.
      Print $cychpTxtFile within two delimiters to see whether that is so: print "[$cychpTxtFile]" for example.
    • There is no drive letter at the start of your filenames. If you are under Windows (as the upper case filenames suggest), did your script maybe change the current drive from C: to something else?
      If you are running under OSX, did you maybe mount an HFS volume under an HFS+ tree?

    If these suggestions yield nothing, you will have to show us how you populate $chunked{$keySets}. Also, why are you so certain that the .txt files exist in that location?

    On the shell, does</c>

    ls "/Users/.../Desktop/cychip/cyto/Oligo/Oligo 2012/eggs/010613ESA ABN +. CONTROL_(CytoScanHD_Array)_2012.cyhd.cychp.txt"
    dir "\Users\...\Desktop\cychip\cyto\Oligo\Oligo 2012\eggs\010613ESA AB +N. CONTROL_(CytoScanHD_Array)_2012.cyhd.cychp.txt"

    find the files?

    Update: I'm wrong and boftx hits the nail on the head. You're using Parallel::ForkManager, and that means that the changes in the child (the push) do not propagate back to the parent. See perlipc for various ways of communicating the information back to the parent.