in reply to File::Where->where_pm failure in forked children?

File::Where relies on DATA. I bet the file pointer is shared among the child processes.

Sorry, I must run, so I can't verify my guess or come up with a solution right now. But hopefully, it will put you on the right path.

Replies are listed 'Best First'.
Re^2: File::Where->where_pm failure in forked children?
by pheller (Initiate) on Mar 15, 2007 at 02:36 UTC
    Good call. I created a local copy of Where.pm, removed the SelfLoader bits and the example code runs without fail.

    Any ideas how to solve this, short of creating a modified version of File::Where?
      Ok, I figured out a solution myself :-)
      #!perl use Parallel::ForkManager; use strict; use warnings; my $pm = new Parallel::ForkManager(2); for my $i (1 .. 3) { my $pid = $pm->start and next; my @ret = (); my $code = "use File::Where; \@ret = File::Where->where_pm(\"File::W +here\");"; eval $code; print $ret[0]."\n"; $pm->finish; } $pm->wait_all_children;
        my @ret = (); my $code = "use File::Where; \@ret = File::Where->where_pm(\"File::W +here\");"; eval $code;

        can be written more readably as:

        eval("use File::Where"); die($@) if $@; my @ret = File::Where->where_pm("File::Where");

        or

        require File::Where; import File::Where; my @ret = File::Where->where_pm("File::Where");

        These two snippets won't hide errors like yours did.