subroutine

Subroutine to connect to MS Access database

I have this subroutine setup to connect to a MS Access database: Public Sub MakeDBConnection(ByVal source As String) Try cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & source & ";") cn.Open() Catch e As Exception ReportError("CRITICAL", e.Message) End Try End Sub It is i...

How can I pass value to Perl Subroutine parameters on command line?

Hi. my test.pl script as below. #!C:\Perl\bin\perl.exe use strict; use warnings; sub printargs { print "@_\n"; } &printargs("hello", "world"); # Example prints "hello world" If I replaced printargs("hello", "world"); with print($a, $b);. How to pass 'hello' ,'world' to $a , $b when I run perl test.pl hello world at comman...

How can I pass a constant to a Perl subroutine?

I have got as follows: use constant ABC => ('one', 'two', 'three'); and I want to pass this constant to variations_with_repetition(\@data, $k) subroutine as @data. How should I do that? ...

What does the function declaration "sub function($$)" mean?

I have been using Perl for some time, but today I came across this code: sub function1($$) { //snip } What does this mean in Perl? ...

Fortran arrays and subroutines (sub arrays)

I'm going through a Fortran code, and one bit has me a little puzzled. There is a subroutine, say SUBROUTINE SSUB(X,...) REAL*8 X(0:N1,1:N2,0:N3-1),... ... RETURN END Which is called in another subroutine by: CALL SSUB(W(0,1,0,1),...) where W is a 'working array'. It appears that a specific value from W is passed to the X, howe...

Is there a Perl idiom which is the functional equivalent of calling a subroutine from within the substitution operator?

Perl allows ... $a = "fee"; $result = 1 + f($a) ; # invokes f with the argument $a but disallows, or rather doesn't do what I want ... s/((fee)|(fie)|(foe)|(foo))/f($1)/ ; # does not invoke f with the argument $1 The desired-end-result is a way to effect a substitution geared off what the regex matched. Do I have to write sub lal...

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 $printScreen = settingsGeneral::printScreen; &$printScreen("test"); but this result int...

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

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 = in...

Can a Perl subroutine return data but keep processing?

Is there any way to have a subroutine send data back while still processing? For instance (this example used simply to illustrate) - a subroutine reads a file. While it is reading through the file, if some condition is met, then "return" that line and keep processing. I know there are those that will answer - why would you want to do tha...

How can I modify a scalar reference passed to a subroutine reference?

I have a function to convert documents into different formats, which then calls another function based on the type document. It's pretty straight forward for everything aside from HTML documents which require a bit of cleaning up, and that cleaning up is different based on where it's come from. So I had the idea that I could pass a refer...

Accessing Sub functions /procedures from DPR or other function / procedure in Delphi

Hello, stackoverflowers :) As much I know - Subroutines are with Private access mode to its parent unction / procedure, right? Is there any way to access them from "outer-world" - dpr or other function / procedure in unit? Also - which way takes more calcualtion and space to compiled file? for example: function blablabla(parameter :...

Fortran intent(inout) v's no intent

Good practice dictates that subroutine arguments in Fortran should each have a specified intent (i.e. intent(in), intent(out) or intent(inout) as described this question): subroutine bar (a, b) real, intent(in) :: a real, intent(inout) :: b b = b + a ... However, not specifying an intent is valid Fortran: subroutine b...

Stopping other subs from running while in a Sub

Is there a way to stop other subs from running while in a separate sub. for instance say your in the sub CreateNumber() and the subs are setup like CreateNumber() AddNumber() DeleteNumber() Is there a way to be in CreateNumber() and call a function to stop AddNumber from running after creaetNumber() is finished? i just want my pro...

How do I get the object that called (executed) my vb.net subroutine inside my object?

I'm trying to extend my new WPF Touch Screen Keyboard (DLL) Library, to allow the user to get events from the Touch Screen Object. I'd like to be able to tell the Programmer what Object made the call (or executed the subroutine) that raised the event. Not dissimilar to the Sender as Object event parameters one gets when working with a Sy...

File::Find and $_ in nested subroutines.

When running the following code, the filenames of all files below C:\Test are printed. Why doesn't it print just Hello (n times, depending on how many files are processed)? Does this imply that I cannot rely on shift to reliably assign to $_? Imagine a coworker implements the wtf function and doesn't know that it's called from a File::...

Global Variable, subroutine variable Question in Perl

Hello. How can I transfer the subroutine variable value into another subroutine variable, Can I use global variable. sub foo(){ my $myvar = "Hello"; } sub foo1(){ my $myvar1 = $myvar; # how can I get the "Hello" from $myvar. } I tried to use package and global variable, but failed. Package Bar; our $bar; Thank you. ...

Matching n parentheses in perl regex

Hi, I've got some data that I'm parsing in Perl, and will be adding more and more differently formatted data in the near future. What I would like to do is write an easy-to-use function, that I could pass a string and a regex to, and it would return anything in parentheses. It would work something like this (pseudocode): sub parse { ...

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 sophisticated { my ($args) = @_; print $args->{m}; print $args->{fh} $args->{m} ; } ...

perl print array from subroutine

#! /usr/local/bin/perl sub getClusters { my @clusters = `/qbo/bin/getclusters|grep -v 'qboc33'`; chomp(@clusters); return \@clusters; } ummm okay .. how do I get at this array to print since ... foreach $cluster (getClusters()) { print $cluster."\n"; } doesn't seem to work. Thanks. ...

Subroutines in MIPS and other beginner silliness

I'm using Project Euler to learn MIPS, specifically using Problem 6 to learn how to use a subroutine. Unfortunately, I am doing something very wrong because my answer that I'm getting is far too large in magnitude. Is my problem here with how I am using the subroutine, or is it something else entirely? ## p6.asm ## ## Andrew Levenson, 2...