in reply to Problem with forking in perl

Hi,

just a side note while looking at your problem. You have the function

sub ProcessRecords() { my ( @acctArray,$myNbr,$totalChilds,$totalAccts) = @_;
and call this function with
ProcessRecords( @SharedPlanAccts, $i1, $n, $totalAccts );
I hope you're aware of the fact that @acctArray slurps ALL args and $myNbr, $totalChilds,$totalAccts will be undef.

For all reading this:

use strict; use warnings; use Data::Dumper; my @list = qw(1 2 3 4); func(@list, 'a', 'b', 'c'); sub func { my (@list, $s1, $s2, $s3) = @_; print Dumper(\@list), "\n"; print Dumper(\$s1), "\n"; print Dumper(\$s2), "\n"; print Dumper(\$s3), "\n"; }

McA

Replies are listed 'Best First'.
Re^2: Problem with forking in perl
by rkrish (Acolyte) on Mar 14, 2013 at 08:51 UTC
    How can I overcome this? How to seperate these variable..? also LoginDB subroutine creates DB connection handle for the child process.

      There are two possibilities

      • Change the parameters, so that the only list assignment is at the end.

        sub ProcessRecords() { my ($myNbr, $totalChilds, $totalAccts, @acctArray) = @_;
        In this case the scalars get one value and the rest is slurped by @acctArray. The sequence of parameters has also to be changed at the calling point.

      • Or you use references:

        sub ProcessRecords() { my ($ref_acctArray,$myNbr,$totalChilds,$totalAccts) = @_;
        and call it with
        ProcessRecords( \@SharedPlanAccts, $i1, $n, $totalAccts );
        You than have to dereference $ref_acctArray with a @$ref_acctArray.

      McA