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

Hi I am working with perl catalyst I am new to this. Now I am facing a problem regarding variables. Here I am getting input as hash. Now I need to send this hash variable to another subroutine. Please help me how could I send. I writing the code below how I am using:
if ($csData->{'CUSTOMER_INVOICE_DETAILS'}) { $c->log->debug("API Response:". Dumper $csData->{'CUSTOMER_INVOICE_DET +AILS'}); my $Charges = []; my @customerCharges = $csData->{'CUSTOMER_INVOICE_DETAILS'}; foreach(@customerCharges) { my ($customername,$customeramount) = split /:/; my $charge_hash = ({ customername => $customername, customeramount => $customeramount }); push(@$Charges, $charge_hash); } my @ReturnCharges = $self->API->get_customer_charges($Charges, $Custom +er->customerid, $params->{'invoiceid'});
The other subroutine where this data is receiving is as following:
sub get_customer_charges { my $self = shift; my ($charge, $CustomerId, $INID) = @_; my $http_request = { action => 'GetTariff', customerid => $CustomerId, csid => $INID, }; my $markups = $self->APIRequest($http_request); ##‪#‎Charge‬ Level ID Inserting As 10 my @ChargeLevels; my @BaseLevelID; foreach my $ch (@$charge) { my ($customername,$customeramount) = split(':', $ch->{'customername'}, + $ch->{'customername'}); my $chargelevel = join(':', $ch->{'customername'}, $ch->{'customeramou +nt'}, '10'); push(@BaseLevelID, $chargelevel); } push(@ChargeLevels, @BaseLevelID); return @ChargeLevels; }
Where I am printing server log for CUSTOMER_INVOICE_DETAILS variable I am getting the following values:
API Response:$VAR1 = { 'Product' => '34.04', 'basetax' => '2.38', 'vattax' => '4.36' };
After sending data to second subroutine the data coming in server log for second subroutine variable is as following: Charges in API:$VAR1 = 'HASH(0xb75d6d8)::10'; Can anyone help how could I send the hash data from one subroutine to another? Thanks in advance.

Replies are listed 'Best First'.
Re: Convert Hash To Array in Perl Catalyst
by choroba (Cardinal) on Mar 27, 2015 at 14:43 UTC
    Crossposted to StackOverflow. It's considered polite to inform about crossposting, so people not attending both sites don't waste time hacking a solution of a problem already solved at the other end of the internet.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Convert Hash To Array in Perl Catalyst
by Laurent_R (Canon) on Mar 27, 2015 at 18:30 UTC
    Your variable appears to be not a hash, but a hash ref (although I am guessing, you're not saying enough). You probably need to dereference it. Something like this:
    sub other_subroutine { my $href = shift; my $product = $href->{Product}; my $tax = $href->{basetax}; # ...

    Je suis Charlie.