subroutine

What is the difference between a subroutine and a function? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-01 03:12:11
Possible Duplicate: What is the difference between a ‘function’ and a ‘procedure’? I searched online for an answer to this question, and the answer I got was that a function can return a value, modify a value, etc., but a subroutine cannot. But I am not satisfied with this explanation and it seems to me that the difference ought to be more than just a matter of terminology. So I am looking for a more conceptual answer to the question. A function mirrors the mathematical definition of a function, which is a mapping from 1 or more inputs to a value. 1 A subroutine is a general-purpose term for

What is the difference between a subroutine and a function? [duplicate]

白昼怎懂夜的黑 提交于 2019-12-01 00:14:09
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: What is the difference between a ‘function’ and a ‘procedure’? I searched online for an answer to this question, and the answer I got was that a function can return a value, modify a value, etc., but a subroutine cannot. But I am not satisfied with this explanation and it seems to me that the difference ought to be more than just a matter of terminology. So I am looking for a more conceptual answer to the

How can I inline Perl subroutines?

喜夏-厌秋 提交于 2019-12-01 00:03:06
问题 I am reading Code Complete 2, and one of the points mentioned is about creating subroutines even for operations that seem too simple to have their own subroutines, and how that can be helpful. I know I can inline functions in C and C++ using the inline keyword. But I never came across a way to inline subroutines in Perl. Is there a way to tell the Perl interpreter to inline the subroutine calls (or why not)? 回答1: Constant subroutines, i.e. subroutines with an empty prototype and constant

VBA Pass Array By Reference and Modify Contents

血红的双手。 提交于 2019-11-30 13:43:55
VBA question. I'm using it to make Solidworks macros, but that's not important. Can someone explain the syntax to pass an array (1-Dimensional of type Double, with length of three) to a subroutine or function so I can modify the contents. I know that they have to be passed by reference. I'm talking exact syntax, because everything I try I get type mismatch error on the subroutine/function call. All I'm looking for is the correct Dim statement for the array of Doubles, initialize statement to make all array values zero, then the subroutine call statement and subroutine header that I would need.

Syntax: “Exit Sub” or “Return” in VB.NET subroutines

自作多情 提交于 2019-11-30 13:35:23
问题 Both "Exit Sub" or "Return" seem to accomplish the same thing -- exit a subroutine. Is there any difference in how they work under the covers? That is, Private Sub exitNow() Exit Sub End Sub or Private Sub exitNow() Return End Sub 回答1: From the doc: In a Sub or Set procedure, the Return statement is equivalent to an Exit Sub or Exit Property statement, and expression must not be supplied. So they're the same in this context. 回答2: I tend to prefer Return over Exit Sub . Because once in a while

Getting all arguments passed to a subroutine as a string in Perl

巧了我就是萌 提交于 2019-11-30 09:26:19
问题 I am trying to write a function that can take all of its arguments and print them as a string exactly as they were entered. For example using the following function: test('arg1' => $arg1, 'arg2' => $arg2); I would like to get the following string inside of the function formatted EXACTLY as seen below : "'arg1' => $arg1, 'arg2' => $arg2" I want to do this so I can print all of the arguments the same way that they were entered for debugging/testing purposes. 回答1: Perl provides special debugging

Syntax: “Exit Sub” or “Return” in VB.NET subroutines

蹲街弑〆低调 提交于 2019-11-30 08:03:46
Both "Exit Sub" or "Return" seem to accomplish the same thing -- exit a subroutine. Is there any difference in how they work under the covers? That is, Private Sub exitNow() Exit Sub End Sub or Private Sub exitNow() Return End Sub From the doc: In a Sub or Set procedure, the Return statement is equivalent to an Exit Sub or Exit Property statement, and expression must not be supplied. So they're the same in this context. I tend to prefer Return over Exit Sub . Because once in a while you change from Sub to Function . In this case Exit Sub could be converted to Exit Function , but this assumes

fortran, passing allocatable arrays to a subroutine with right bounds

♀尐吖头ヾ 提交于 2019-11-30 07:31:52
I need in a program to pass some allocatable arrays to subroutines, and i need to know if the way I do it are in the standard or not. If you know where I can search for the standard of fortran, Tell me please. Here is a little code that will better explain than words program test use modt99 implicit none real(pr), dimension(:), allocatable :: vx allocate(vx(-1:6)) vx=(/666,214,558,332,-521,-999,120,55/) call test3(vx,vx,vx) deallocate(vx) end program test with the module modt99 module modt99 contains subroutine test3(v1,v2,v3) real(pr), dimension(:), intent(in) :: v1 real(pr), dimension(0:),

VBA Pass Array By Reference and Modify Contents

笑着哭i 提交于 2019-11-29 18:37:34
问题 VBA question. I'm using it to make Solidworks macros, but that's not important. Can someone explain the syntax to pass an array (1-Dimensional of type Double, with length of three) to a subroutine or function so I can modify the contents. I know that they have to be passed by reference. I'm talking exact syntax, because everything I try I get type mismatch error on the subroutine/function call. All I'm looking for is the correct Dim statement for the array of Doubles, initialize statement to

Perl not printing properly

放肆的年华 提交于 2019-11-29 12:07:42
Ok, so I have some sub routines similar to what you see below, my issue is that the print function is not printing out until the actual command is complete, I want it to print "Has MySQL, Installing:", and then do the command then print OK. I have already tried using sleep and tried clearing the $ssh_d object. Any advice appreciated. Don't worry about the variables in this particular sub, the issue is happening all over. Thanks guys. if ($MySQL) { print "Has MySQL, Installing: "; $mysqlCmd = "/path/to/script/mysql-install.pl $person > /dev/null 2>&1"; $ssh_d->cmd("$mysqlCmd"); print "OK\n"; }