Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Problem with forking in perl

by McA (Priest)
on Mar 14, 2013 at 08:00 UTC ( [id://1023413]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1023413]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-29 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found