subroutine

The name of a subroutine can be a variable in Fortran? [duplicate]

瘦欲@ 提交于 2020-04-06 01:54:45
问题 This question already has answers here : How to alias a function name in Fortran (2 answers) Closed 4 years ago . I was wondering if there is something similar to this in Fortran. Of course this example does not compile but I think you can get the idea. program test character(1):: sub sub='A' call sub sub='B' call sub end program subroutine A print*,'OK! A' end subroutine A subroutine B print*,'OK! B' end subroutine B 回答1: You cannot accomplish this by setting a character variable, but you

Do I always have to provide Tkx's -command argument an anonymous subroutine?

為{幸葍}努か 提交于 2020-03-16 07:27:07
问题 I find it a bit weird that I have to wrap defined subroutines anonymously when specifying the -command argument for Tkx widgets. An excerpt from a TkDocs tutorial demonstrates this: my $cb = $frm->new_ttk__button ( -text => "Calculate", -command => sub {calculate();} ); sub calculate { $meters = int(0.3048*$feet*10000.0+.5)/10000.0 || ''; } Why doesn't it work when I write -command => &calculate() or -command => \&calculate() ? 回答1: You don't have the syntax quite right. Your examples call

How to know the procedure by which subroutine called? in excel vba

落爺英雄遲暮 提交于 2020-02-25 05:51:05
问题 I sometimes has error on subroutine.The subroutine is called by many procedure. So, I try to find caller procedure for step over. By the way, user-defined function can know the caller. It is simply. MsgBox Application.Caller We can see dialog and caller cell address. I want to know caller procedure of subroutine. 回答1: You can use Call Stack Dialog Box For example in the below image proc3 was called by proc2 which is displayed in call stack dialog box. 来源: https://stackoverflow.com/questions

How do you pass a parameter back from an external assembler subroutine to a cobol program?

拜拜、爱过 提交于 2020-01-15 04:01:06
问题 I am trying to pass back a parameter from an external subroutine written in assembler. The calling routine is in cobol, and the parameters to the external assembler routine look like this: 01 CALCSHRS-PARMS. 05 CS-DEPOSIT-AMT PIC 9(5)V99 COMP-3. 05 CS-SHARE-PRC PIC 9(3)V99 COMP-3. 05 CS-SHARE-AMT PIC 9(9)V99 COMP-3. The call looks like this: CALL 'CALCSHRS' USING CS-DEPOSIT-AMT CS-SHARE-PRC CS-SHARE-AMT. The routine uses the CS-DEPOSIT-AMT and the CS-SHARE-PRC to calculate the CS-SHARE-AMT,

Default argument values in subroutines

偶尔善良 提交于 2020-01-12 06:49:06
问题 I don't know how to set default arguments for subroutines. Here is what I considered: sub hello { print @_ || "Hello world"; } That works fine for if all you needed was one argument. How would you set default values for multiple arguments? I was going to do this: sub hello { my $say = $_[0] || "Hello"; my $to = $_[1] || "World!"; print "$say $to"; } But that's a lot of work... There must be an easier way; possibly a best practice? 回答1: I do it with named arguments like so: sub hello { my (

Open a workbook using FileDialog and manipulate it

岁酱吖の 提交于 2020-01-10 05:33:05
问题 I found this code here on StackOverflow: Dim fd As Office.FileDialog Set fd = Application.FileDialog(msoFileDialogFilePicker) With fd .AllowMultiSelect = False .Title = "Please select the file to kill his non colored cells" .Filters.Add "Excel", "*.xls" .Filters.Add "All", "*.*" If .Show = True Then txtFileName = .SelectedItems(1) End If End With I know this code should select a file in FileDialog . However, once I have chosen the .xls file, how do I manipulate the file? In other words, where

What is wrong with this Perl subroutine?

懵懂的女人 提交于 2020-01-07 08:35:09
问题 I'm trying to implement a subroutine that calculates the d-neighbors of an input string. This is apart of an implementation of planted motif search, but my question is much more general. Here is the code: #subroutine for generating d-neighbors sub generate_d_neighbors{ # $sequence is the sequence to generate d-neighbors from # $HD is the Hamming Distance my ($sequence, $HD) = @_; for(my $i = 0; $i=$HD; $i++){ my @l = ['A', 'C', 'T', 'G']; my @t = splice(@l,$sequence[$i]); #TODO } } The error

Is it possible to redefine subroutines to be localized for a part of the code?

和自甴很熟 提交于 2020-01-05 06:45:07
问题 Is it possible to redefine the _function_used_by_exported_function only for the exported_function call in the second_routine ? #!/usr/bin/env perl use warnings; use strict; use Needed::Module qw(exported_function); sub first_routine { return exported_function( 2 ); } no warnings 'redefine'; sub Needed::Module::_function_used_by_exported_function { return 'B'; } sub second_routine { return exported_function( 5 ); } say first_routine(); say second_routine(); 回答1: You can locally redefine the

Is it possible to redefine subroutines to be localized for a part of the code?

烂漫一生 提交于 2020-01-05 06:45:06
问题 Is it possible to redefine the _function_used_by_exported_function only for the exported_function call in the second_routine ? #!/usr/bin/env perl use warnings; use strict; use Needed::Module qw(exported_function); sub first_routine { return exported_function( 2 ); } no warnings 'redefine'; sub Needed::Module::_function_used_by_exported_function { return 'B'; } sub second_routine { return exported_function( 5 ); } say first_routine(); say second_routine(); 回答1: You can locally redefine the

How to use a 'subroutine reference' as a hash key

。_饼干妹妹 提交于 2020-01-04 16:57:11
问题 In Perl, I'm learning how to dereference 'subroutine references'. But I can't seem to use a subroutine reference as a hash 'key'. In the following sample code, I can create a reference to a subroutine ($subref) and then dereference it to run the subroutine (&$subref) I can use the reference as a hash 'value' and then easily dereference that But I cannot figure out how to use the reference as a hash 'key'. When I pull the key out of the hash, Perl interprets the key as a string value (not a