Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Answer: How can I write a function's output to a scalar?

( #181441=categorized answer: print w/ replies, xml ) Need Help??

Q&A > subroutines > How can I write a function's output to a scalar? contributed by ackohno

The question is a bit vague, I assume you mean to do something like this:
#!/usr/bin/perl -w use strict; my ($num1,$num2); $num1=2; $num2=sum($num1,$num1); print "$num2\n"; # Sum: returns the sum of all arguments. sub sum { my $ret; $ret=0; for(@_){$ret+=$_} return $ret; }
return tells perl what the subroutine should give back when called, so $num2 is given the final value of $ret in the subroutine sum.

Comment on Answer: How can I write a function's output to a scalar?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-07-28 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (210 votes), past polls