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

Hello,

I have function with return value like below :

return { red => { sla => $sla_red, eta => $eta_red, pending => $red +_pending}, green => { sla => $sla_green, eta => $eta_gr +een, pending => $green_pending}, };

I want to take only $sla_red and $sla_green each time the function calls in another cgi file. Please help me doing this.

Replies are listed 'Best First'.
Re: Taking individual values from return of a function
by McA (Priest) on Dec 10, 2013 at 08:26 UTC

    Hi,

    what keeps you away from just taking these two values?

    You could use a wrapper if you need:

    sub your_wrapper { my $ret = your_function(@_); return ($ret->{red}->{sla}, $ret->{green}->{sla}); } my ($val1, $val2) = your_wrapper('bla', 'blub');

    Regards
    McA

      Possibly lack of knowledge about reference usage.

        Possibly the stupidest answer of the day.

        Karl

        «The Crux of the Biscuit is the Apostrophe»

Re: Taking individual values from return of a function
by davido (Cardinal) on Dec 10, 2013 at 08:31 UTC

    I want to take only $sla_red and $sla_green each time the function calls...

    my $href = function_call(); my( $red, $green ) = map { $href->{$_}{sla} } qw( red green );

    ...in another cgi file.

    That last part is too vague. Please clarify.


    Dave

      The function is written in one file and i want the variables in another file.

        ... i want the variables in another file.

        That's still too vague for me to understand. Do you mean "I want the values of the variables to be written to another file", or "I want to access those variables from a part of my program contained in another file", or ...?

Re: Taking individual values from return of a function
by Anonymous Monk on Dec 10, 2013 at 08:28 UTC