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

sub wind_Up { my( $self, $copyLocation, $tcid, %parseData, $actRecordType, %cdrHash +) = @_ ; .... ....}
and accessing the subroutine over an object as follows
$obj->wind_Up( $LOGPATH, $test_id, %matchData, $recordType, %recordHas +h );
But I always observe that I am losing the last hash that is been passed. As subroutine does not get this value. I tried by replacing the last hash by a scalar but still observe the same result. Can you let me know what is the mistake in above code? and any possible solution for the same? Naresh

Replies are listed 'Best First'.
Re: passing hashes, scalars and arrays to subroutine
by toolic (Bishop) on Jan 20, 2010 at 18:09 UTC
    Your %parseData hash is gobbling up the rest of the list from @_. You could pass the 2 hashes by reference:
    $obj->wind_Up( $LOGPATH, $test_id, \%matchData, $recordType, \%recordH +ash ); ... sub wind_Up { my( $self, $copyLocation, $tcid, $parseDataRef, $actRecordType, $cdrHa +shRef ) = @_ ; .... ....}
    See also:
    perlreftut
    Pass by Reference
Re: passing hashes, scalars and arrays to subroutine
by kennethk (Abbot) on Jan 20, 2010 at 18:15 UTC
    When you call or return from a Perl subroutine, your argument list gets flattened into a simple list. For your argument list as presented, this means that the first three elements of your argument list are assigned to $self, $copyLocation, and $tcid and the remaining elements of the argument list are assigned to %parseData. If you want to pass multiple arrays or hashes, you need to use Pass by Reference. See perlreftut for more info on references and perlsub for more info on Perl subroutines.
      It's solved, Thank you very much for your suggestion.