Home: Perl Programming Help: Beginner:
Can sub return more then one value?



digioleg54
User

May 3, 2017, 1:16 PM


Views: 1565
Can sub return more then one value?

Can the sub return one, two or even more values and how? How can I catch values in the main program?

Thanks


(This post was edited by digioleg54 on May 3, 2017, 1:21 PM)


FishMonger
Veteran / Moderator

May 3, 2017, 2:25 PM


Views: 1553
Re: [digioleg54] Can sub return more then one value?

Yes, a sub can return a list of values.

Code
return $var1, $var2, $var3;



Code
my @list_of_values = my_subroutine();

or

Code
my ($v1, $v2, $v3) = my_subroutine();


Code



      
    


Laurent_R
Veteran / Moderator

May 3, 2017, 3:06 PM


Views: 1549
Re: [digioleg54] Can sub return more then one value?

Dear digioleg54,
I am sure happy to answer your questions. But I have the feeling that in many cases, you don't do your homework before asking. Maybe you should make an effort trying to find the answer before asking.

Or, rather, maybe you should take the time to read a good tutorial on Perl before asking any question. Or even an introductory book on Perl. I'm pretty sure you'll save quite a bit of time reading a good introduction to Perl, rather than just asking basic questions on this forum.

Please make some effort trying to understand Perl with the right tutorial or book, then your questions will be hopefully more precise and more pointed, and we will be able and have the pleasure to provide better answers.