subroutine

Pass variable from a child to parent in KSH

你。 提交于 2019-11-28 11:50:49
问题 I have to work with KSH (yeah that hell shell). I need to use a fork, a subroutine as following: #!/bin/ksh PIPE=PIPE_$$ PIPE_ERR=PIPE_ERR_$$ export TEST_FILS $(. ./LanceFils.ksh 2>${PIPE_ERR} 1>${PIPE}) & PID_CHILD=$! echo "Nom du fichier PIPE: ${PIPE}" echo "Processus fils : " $! wait ${PID_CHILD} echo "Code retour: " $? echo "Sortie standard de PROC_FILS : " $(cat ${PIPE}) echo "Sortie d'erreur(s) de PROC_FILS : " $(cat ${PIPE_ERR}) echo "Contenu de TEST_FILS: ${TEST_FILS}" rm -rf ${PIPE}

Asterisks in Fortran: Syntax error in argument list at (1)

回眸只為那壹抹淺笑 提交于 2019-11-28 11:33:00
问题 In the following fortran77 code, there is this subroutine definition SUBROUTINE MSIRNS ( D , NOBST , N , X , R , RR , SURFT , , INOBSI , ISUR , IDELTS , IRELPS , , RNOBSI , RSUR , RDELTS , RRELPS , , OBSD , * , * ) what is the meaning of the two last arguments, asterisks? and how can I therefore call the function? I tried all these variants RES = CALL MSIRNS (D, NOBST, N, X, R, RR, SURFT, INOBSI, ISUR, IDELTS, IRELPS, RNOBSI, RSUR, RDELTS, RRELPS, OBSD, *, *) CALL MSIRNS (D, NOBST, N, X, R,

Perl - What scopes/closures/environments are producing this behaviour?

空扰寡人 提交于 2019-11-28 10:22:26
问题 Given a root directory I wish to identify the most shallow parent directory of any .svn directory and pom.xml . To achieve this I defined the following function use File::Find; sub firstDirWithFileUnder { $needle=@_[0]; my $result = 0; sub wanted { print "\twanted->result is '$result'\n"; my $dir = "${File::Find::dir}"; if ($_ eq $needle and ((not $result) or length($dir) < length($result))) { $result=$dir; print "Setting result: '$result'\n"; } } find(\&wanted, @_[1]); print "Result: '

How can I write a Perl script to extract the source code of each subroutine in a Perl package?

痞子三分冷 提交于 2019-11-28 10:20:32
Given a Perl package Foo.pm, e.g. package Foo; use strict; sub bar { # some code here } sub baz { # more code here } 1; How can I write a script to extract the textual source code for each sub, resulting in a hash: $VAR1 = { 'bar' => 'sub bar { # some code here }', 'baz' => 'sub baz { # more code here }' }; I'd like to have the text exactly as it appears in the package, whitespace and all. Thanks. PPI is kind of a pain to work with at the very first; the documentation is not good at telling you which class documents which methods shown in the examples. But it works pretty well: use strict; use

how to compile multi-folder Fortran Project having interfaces, modules and subroutines

青春壹個敷衍的年華 提交于 2019-11-28 10:20:32
I am new to Fortran. I am working on a research project where I am using an open source project that has several files distributed in multiple folders. i found the dependency of each programs but could not figure out how to compile them. I have source code distributed in three folders. a)modules b)interfaces c)subroutines I would like to run a program named as 'Main.f90' in subroutines folder, this program has dependency of source codes from modules and interfaces folders. I am using eclipse for folder structure and makefile to compile. Any help with this is appreciated. UPDATE: I followed the

How to pass optional parameters to a Perl function?

删除回忆录丶 提交于 2019-11-28 07:35:18
I want to pass several parameters, one of which is optional, to a function. The only way to do it that I know is using a list (@) as a parameter. Thus, it contents nothing or 1 element (will never be undef), so that I can use the following code: sub someFunction($$@) { my ( $oblig_param1, $oblig_param2, $option_param ) = @_; ... } This code works, but I feel that maybe it's not the best workaround. Are there any other ways to do it? Thank you. You can use a semicolon in the prototype to indicate the end of the required parameters: sub someFunction($$;$) { my ( $oblig_param1, $oblig_param2,

Nested subroutines and Scoping in Perl

吃可爱长大的小学妹 提交于 2019-11-28 07:33:56
I'm writing Perl for quite some time now and always discovering new things, and I just ran into something interesting that I don't have the explanation to it, nor found it over the web. sub a { sub b { print "In B\n"; } } b(); how come I can call b() from outside its scope and it works? I know its a bad practice to do it, and I dont do it, I use closured and such for these cases, but just saw that. Ven'Tatsu Subroutines are stored in a global namespace at compile time. In your example b(); is short hand for main::b(); . To limit visibility of a function to a scope you need to assign an

Why would I use Perl anonymous subroutines instead of a named one?

点点圈 提交于 2019-11-28 07:33:06
I'm just curious why one would choose to use an anonymous subroutine, versus a named one, in Perl. Thanks. innaM You can store anonymous subs in arrays, hashes and scalars. You can build them at runtime You can pass them as arguments to other functions. You get to keep variables in the surrounding scope. The last point is probably the most important, because it's often the most unexpected facet of named vs. anonymous subroutines in Perl. Example: sub outer { my $a = 123; sub inner { print $a, "\n"; } # At this point, $a is 123, so this call should always print 123, right? inner(); $a = 456; }

Perl not printing properly

强颜欢笑 提交于 2019-11-28 05:43:01
问题 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 =

Calling an internal subroutine inside OpenMP region

倾然丶 夕夏残阳落幕 提交于 2019-11-28 01:55:35
问题 I have a module that contains a subroutine that contains another subroutine. The outer subroutine has a parallel OpenMP region in which I call the inner subroutine. The code compiles and runs without any error but the results are not correct. module my_module contains subroutine a(...) *...some variables* !$OMP PARALLEL DO DEFAULT(PRIVATE) SHARED(...) *...do some work* call b(...) !$OMP END PARALLEL DO contains subroutine b(...) *...some variables* *...do some work* end subroutine b end