argument

is there a way to write macros with a variable argument list in visual C++?

As far as I know, in gcc you can write something like: #define DBGPRINT(fmt...) printf(fmt); Is there a way to do that in VC++? ...

Confusing evaluation of $args in PowerShell

The $args variable should, by definition, contain all arguments passed to a script function. However if I construct a pipeline inside my function, the $args variable evaluates to null. Anyone knows why? See this example: function test { 1..3 | % { echo "args inside pipeline: $args" } ; echo "args outside pipeline: $args" } This is th...

list named with a function argument in python

I get the feeling this is probably something I should know but I can't think of it right now. I'm trying to get a function to build a list where the name of the list is an argument given in the function; e.g. def make_hand(deck, handname): handname = [] for c in range(5): handname.append(deck.pop()) return handname ...

How can I parse command-line switches in Perl?

In order to extend my "grep" emulator in Perl I have added support for a -r switch which enables recursive searching in sub-directories. Now the command line invocation looks something like this: perl pgrep.pl -r <directory> <expression> Both -r and the directory arguments are optional (directory defaults to '.'). As of now I simply c...

Validating function arguments?

On a regular basis, I validate my function arguments: public static void Function(int i, string s) { Debug.Assert(i > 0); Debug.Assert(s != null); Debug.Assert(s.length > 0); } Of course the checks are "valid" in the context of the function. Is this common industry practice? What is common practice concerning function argumen...

Argument Checking Problem in Bash Script

So basically I am trying to check the arguments that are passed into the script. If it has three arguments and the third argument is a 1, then I want it to continue. I also want it to continue if it has four arguments and the third argument is not a 1. So basically I thought that I could just do... if ([ $# -ne 3 ] and [ "$3" -ne "2"...

How to have arguments supplied to .exe passed on to a wrapped .bat script

I'd like to wrap a MyBatScript.bat script inside a MyTest.exe. Then I'd like to invoke MyTest.exe with arguments, thus: MyTest.exe arg1 arg2 format of passing arguments can be different if need be. I'd like arg1 and arg2 to be passed on to MyBatScript.bat as %1 and %2 and MyBatScript.bat executed. How Can I do this? Thanks! ...

passing a command to gdb when running a program

I am using gdb to debug a program, and I want to have the output of the command $(perl -e 'print "A"x20') as my argument. How can I do that? This way the argument would be very flexible. ...

Is there any way to pass an anonymous array as an argument in C++?

Hi all, I'd like to be able to declare an array as a function argument in C++, as shown in the example code below (which doesn't compile). Is there any way to do this (other than declaring the array separately beforehand)? #include <stdio.h> static void PrintArray(int arrayLen, const int * array) { for (int i=0; i<arrayLen; i++) p...

Problem executing TCL script from Bourne Shell (redirection trouble)

I am working with VMD (a molecular dynamics visualization package) and I want to open VMD from a Perl script, run a Tcl script, print the output to a log file, then close VMD and return to the Perl script. The ordinary syntax to do this is: system("vmd -dispdev text -eofexit < program.tcl > LOG"); which breaks down as follows, as best...

Recommendations for Acquiring Concepts?

This somewhat parallels a semi-frequent discussion on /.. What languages are recommended for someone to learn, based on their concepts, to become a programmer; for instance, many on /. note how object oriented programming seems to them to have 'corrupted' the minds of programmers, and that yes it's a great tool, but only if used appropri...

Supplied argument is not a valid MySQL result resource???

I get this error when I use this code for people to input data. The submit form won't be listed cause it's not useful in this circumstance: function some_more_custom_content() { $output="<BR>"; ob_start(); if ($_REQUEST['code'] != "") { $code = $_REQUEST['code']; $query="INSERT INTO `fc` (`code`,`datetime`) values ('" . mysq...

How do I get arguments in a form application?

Hi, I can find many examples on how to get arguments in a console application, but I can't seem to find an example of how to get arguments in a windows form application. I would like to following things. whenever I open a jpg file, windows launches my application. I would like to know path and name of the jpg file from my application...

sizeof() And Template Argument In ctor / Non-ctor Function

I hit a snag today... I wanted to define a small templated helper class: template<class T> CMyClass { public : CMyClass() { size_t iSize = sizeof(T); } // Allowed. size_t GetElementSize() const { return sizeof(T); } // C2027. }; and of course, it wouldn't compile (C2027). My question was, is it possible to get the size of t...

pythonic way to convert variable to list

I have a function whose input argument can either be an element or a list of elements. If this argument is a single element then I put it in a list so I can iterate over the input in a consistent manner. Currently I have this: def my_func(input): if not isinstance(input, list): input = [input] for e in input: ... I a...

Redirecting output to a command-line argument of another command in Windows

How can I, in Windows, use the output of a script/command as an argument for another script? (A pipe | will not work here, since that other script doesn't read from the standard input) Too clarify: I have AnotherScript that needs an argument arg, e.g.: AnotherScript 12 now I want the argument (12 in the example) to come from the outp...

Where to perform argument validation in JavaScript?

Yeah, read properly. In the last time I saw different patterns of argument validation in JavaScript (functions) and wondered which of them would be best-practice. At first I'll show two example code snippets. The first shows an (in my words) "immediate" argument/condition validation and the second one a "delayed" validation. Each of them...

Python object intialization bug. Or am I misunderstanding how objects work?

1 import sys 2 3 class dummy(object): 4 def __init__(self, val): 5 self.val = val 6 7 class myobj(object): 8 def __init__(self, resources): 9 self._resources = resources 10 11 class ext(myobj): 12 def __init__(self, resources=[]): 13 #myobj.__init__(self, resources) 14 ...

How do you specify a required switch (not argument) with Ruby OptionParser?

Say I'm writing a script and I want to require a --host switch (with value of course) but if the --host switch isn't specified I want the option parsing to fail. I can't seem to figure out how to do that. The docs seem to only specify how to make the argument value mandatory, not the switch itself. ...

String arguments in python multiprocessing

I'm trying to pass a string argument to a target function in a process. Somehow, the string is interpreted as a list of as many arguments as there are characters. This is the code: import multiprocessing def write(s): print s write('hello') p = multiprocessing.Process(target=write, args=('hello')) p.start() I get this output:...