A subroutine (e.g. procedure or subprogram) is a portion of code within a larger program, which performs a specific task and can be relatively independent of the remaining code. The syntax of many programming languages includes support for creating self contained subroutines, and for calling and returning from them. They are in many ways similar to functions, but usually have side-effects outside of the simple "return value" that functions return.
Questions tagged [subroutine]
1255 questions
7
votes
3 answers
Perl Unit Testing -- is the subroutine testable?
I have been reading up and exploring on the concept of unit testing and test driven development in Perl. I'm looking into how I can incorporate the testing concepts into my development. Say I have a Perl subroutine here:
sub perforce_filelist {
…

Jon J
- 445
- 3
- 14
7
votes
3 answers
Perl: How to call a specific method in multiple inheritance?
I have a package in perl , which uses two other package as its base.
Parent1:
package Parent1;
use strict;
use warnings;
sub foo
{
my $self = shift;
print ("\n Foo from Parent 1 ");
$self->baz();
}
sub baz
{
my $self = shift;
…

Jayakanthan R
- 95
- 1
- 3
- 8
7
votes
1 answer
How to pass an anonymous enumerated type into a subroutine?
I'm trying to make a convenient function to convert a System.Classes.TShiftState into a user-readable string. To make it easier, I've made a subroutine to perform common code, to make the function more compact.
The problem is, I cannot figure out…

Jerry Dodge
- 26,858
- 31
- 155
- 327
7
votes
1 answer
What is the difference between ESP and EIP registers
What is the difference between ESP and EIP registers using the following examples? Explain what the code is doing.
main PROC
0000 0020 call MySub
0000 0025 mov eax, ebx
.
.
main ENDP
MySub PROC
0000 0040 mov eax,…

jackson blackson
- 311
- 1
- 3
- 13
7
votes
2 answers
How to pass subroutine names as arguments in Fortran?
What is the syntax for passing subroutine names as arguments? Schematically:
.
.
call action ( mySubX ( argA, argB ) )
.
.
subroutine action ( whichSub ( argA, argB ) )
...
call subroutine whichSub ( argA, argB )
...
end subroutine…

dantopa
- 616
- 7
- 19
7
votes
7 answers
Subroutine recursion in Perl
EDIT: I'm glad no one has spent any time pointing out that the actual text in line 6 and 7 has a different number than the input for their respective function calls. Eventually I'll be doing it for those two numbers (724 and 27), but for the sake of…

frankenstein724
- 71
- 4
7
votes
1 answer
Omitting public modifier in java methods
I am learning Java and there's something bothering me and the textbook doesn't explain it.
I understand that you use modifiers to declare methods inside classes and all. But I suddenly got to a class declared like
static void(){
}
Why is there no…

mateo_io
- 398
- 2
- 3
- 12
7
votes
2 answers
Perl: How to pass and use a lexical file handle to a subroutine as a named argument?
I want to pass a lexical file handle to a subroutine using a named argument, but the following does not compile:
#!/usr/bin/perl -w
use strict;
my $log_fh;
my $logname = "my.log";
sub primitive {
my ($fh, $m) = @_;
print $fh $m;
}
sub…

Thomas L Holaday
- 13,614
- 6
- 40
- 51
7
votes
5 answers
Perl calling methods with and without parentheses
Some Perl books advise using parentheses when calling class methods, saying this helps to keep the parser from having to guess the intent of the code. However almost all Perl code I have seen (including modules on cpan) very rarely uses the…

daliaessam
- 1,636
- 2
- 21
- 43
7
votes
5 answers
Calling perl subroutines from the command line
Ok so i was wondering how i would go about calling a perl subroutine from the command line. So if my program is Called test, and the subroutine is called fields i would like to call it from the command line like.
test fields

Mitchk
- 97
- 1
- 1
- 6
7
votes
3 answers
Detect how a subroutine is called in Perl
I would like to detect how a subroutine is called so I can make it behave differently depending on each case:
# If it is equaled to a variable, do something:
$var = my_subroutine();
# But if it's not, do something else:
my_subroutine();
Is that…

calvillo
- 892
- 1
- 9
- 23
7
votes
1 answer
Can we avoid creating a local variable if an optional argument is not PRESENT?
I am having a problem with the PRESENT statement with Fortran 95. Currently I am using Silverfrost's Plato and their FTN95 compiler (in "Release Win32" mode). What I wanted to do is to create a subroutine SUB(a,b), where b is an optional variable.…

gilbertohasnofb
- 1,984
- 16
- 28
7
votes
3 answers
perl subroutine argument lists - "pass by alias"?
I just looked in disbelief at this sequence:
my $line;
$rc = getline($line); # read next line and store in $line
I had understood all along that Perl arguments were passed by value, so whenever I've needed to pass in a large structure, or pass in a…

Chap
- 3,649
- 2
- 46
- 84
7
votes
1 answer
perl assignment to hash in subroutine return gets weird
Running perl 5.12.4
Am getting disparity between result of a function when a hash is assigned within the return statement or beforehand. Easiest example is:
perl -e 'sub s1 {
my @a=qw/b 1 c 2 a 3 a 4/;
my %h=@a;
return %h
}
print "@{[…

Rob N
- 98
- 5
6
votes
2 answers
Subroutine with same name in 2 different CPAN modules
I am getting this error when running perl:
[Thu Mar 16 00:24:23 2023] list_directory_1.cgi: Subroutine
main::getcwd redefined at /usr/lib/cgi-bin/list_directory_1.cgi line
15.
I think it is coming from the fact that getcwd is defined in CPAN…

Marcos Camargo
- 133
- 9