Questions tagged [subroutine]

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.

1255 questions
11
votes
2 answers

Line truncated, Syntax error in argument list

When I compile the program below, I have an error and a warning in the call Coor_Trans command line as Warning: Line truncated Error: Syntax error in argument list I compile the program several times, but it does not work. Maybe there is something…
Jeremy_Tamu
  • 725
  • 1
  • 8
  • 21
11
votes
5 answers

How can I create a Perl subroutine that accepts more than one block?

With prototypes, you can create a subroutine that accepts a block of code as its first parameter: sub example (&) { my $code_ref = shift; $code_ref->(); } example { print "Hello\n" }; How can I do the same thing, but with more than one block…
Flimm
  • 136,138
  • 45
  • 251
  • 267
11
votes
2 answers

Pass regex into perl subroutine

The Situation I am in the process of creating a simple template file that will aid in creating future scripts for doing various tasks via command line on *nix systems. As part of this, I might like to ask the user to input data which needs to…
djthoms
  • 3,026
  • 2
  • 31
  • 56
10
votes
1 answer

Why can't a sub access dynamic variables when used in a "return"ed map in raku?

It seems that a a sub cannot access dynamic variables when it is used inside a map and that map is "return"ed. Consider this piece of code: sub start { my $*something = 'foobar'; # WORKS say 'first say-something:'; …
Julio
  • 5,208
  • 1
  • 13
  • 42
10
votes
2 answers

Can methods be treated as regular subroutines?

Is it possible to assign methods to variables and pass them around as arguments inside the class similar to subroutines? I know they're are accessible by either self. or self! (or whatever named explicit invocant) inside other methods but I'm…
uzluisf
  • 2,586
  • 1
  • 9
  • 27
10
votes
3 answers

How does @_ work in Perl subroutines?

I was always sure that if I pass a Perl subroutine a simple scalar, it can never change its value outside the subroutine. That is: my $x = 100; foo($x); # without knowing anything about foo(), I'm sure $x still == 100 So if I want foo() to change…
David B
  • 29,258
  • 50
  • 133
  • 186
10
votes
1 answer

Contains statement

I am not understanding the importance of CONTAINS statement in fortran 90 For example PROGRAM BLABLA IMPLICIT NONE INTEGER :: i,j,k i = 1; j = 1;k =1 PRINT *, i,j,k CALL ABC(i,j,k) PRINT *, i,j,k CONTAINS SUBROUTINE ABC(r,s,t) …
Vaidyanathan
  • 379
  • 3
  • 6
  • 16
10
votes
1 answer

How can I take a reference to a Perl subroutine?

I'm having some trouble figuring out how to make a reference to a subroutine in an external module file. Right now, I'm doing this: External file package settingsGeneral; sub printScreen { print $_[0]; } Main use settingsGeneral; my…
Pmarcoen
  • 1,216
  • 4
  • 20
  • 33
10
votes
1 answer

Which is the diffeence between an INTERFACE block and a MODULE procedure in fortran?

I'm a bit confused about the use of an interface block inside a module and the use of the CONTAINS statement to create an "explicit interface" for a procedure inside a module. I usually write a procedure using an interface block inside a module. For…
Granados
  • 117
  • 1
  • 7
9
votes
6 answers

restore the previous echo status

In a DOS Batch File subroutine, how can I turn off echo within the subroutine, but before returning, put it back to what it was before (either on or off)? For example, if there was a command called echo restore, I would use it like this: echo on ...…
JoelFan
  • 37,465
  • 35
  • 132
  • 205
9
votes
5 answers

How can I distinguish between an argument that was not passed and one that was passed with a false value?

I am trying to figure the best way to differeniate in Perl between cases where an argument has not been passed, and where an argument has been passed as 0, since they mean different things to me. (Normally I like the ambiguity, but in this case I'm…
Stephen
  • 8,508
  • 12
  • 56
  • 96
9
votes
1 answer

How does the scope effect EVAL of an infix:<> sub?

This code works as expected: sub infix:(*@a) { @a.sum / @a.elems } sub Mean (*@a) { @a.sum / @a.elems } say EVAL 'Mean 2, 6, 4'; # Output: 4 say EVAL '2 mean 6 mean 4'; # Output: 4 It works as expected when line 7 is in its own…
Jim Bollinger
  • 1,671
  • 1
  • 13
9
votes
3 answers

Is Fortran return statement obsolete?

I just want to know if the return statement in Fortran 2008 is obsolete, because it seems to be unnecessary to write it at the end of subroutines and functions. Does it have some other utility?
rsaavedra
  • 378
  • 1
  • 4
  • 12
9
votes
1 answer

Passing size as argument VS assuming shape in Fortran procedures

I'm trying to decide which one of these two options would be the best: subroutine sqtrace( Msize, Matrix, Value ) integer, intent(in) :: Msize real*8, intent(in) :: Matrix(Msize, Msize) real*8, intent(out) :: Value …
Nordico
  • 1,226
  • 2
  • 15
  • 31
9
votes
3 answers

Check if a subroutine is being used as an lvalue or an rvalue in Perl

I'm writing some code where I am using a subroutine as both an lvalue and an rvalue to read and write database values. The problem is, I want it to react differently based on whether it is being used as an lvalue or an rvalue. I want the subroutine…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98