parameter-passing

Getting all arguments passed to a subroutine as a string in Perl

巧了我就是萌 提交于 2019-11-30 09:26:19
问题 I am trying to write a function that can take all of its arguments and print them as a string exactly as they were entered. For example using the following function: test('arg1' => $arg1, 'arg2' => $arg2); I would like to get the following string inside of the function formatted EXACTLY as seen below : "'arg1' => $arg1, 'arg2' => $arg2" I want to do this so I can print all of the arguments the same way that they were entered for debugging/testing purposes. 回答1: Perl provides special debugging

Pass array to ParamArray

倾然丶 夕夏残阳落幕 提交于 2019-11-30 08:27:03
is it possible to pass all elements of an array to a ParamArray? For example I'd like to pass a ParamArray to another ParamArray: Sub test() p1 "test", "banane", "birne" End Sub Sub p1(ParamArray keys() As Variant) p2 keys 'should be the same as: p2 "test", "banane", "birne" End Sub Sub p2(ParamArray keys() As Variant) Dim key As Variant For Each key In keys Debug.Print key 'Run-time error '13' Type mismatch (key is an array) Next key End Sub In this case ParamArray of p2 doesn't contain the elements of keys , but it gets the array-object keys . Thus I've got to check, if an arrays is passed:

How to work with infinity arguments in a function (like PHP's isset())

自作多情 提交于 2019-11-30 07:59:15
You know how PHP's isset() can accept multiple (no limit either) arguments? Like I can do: isset($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11); //etc etc How would I be able to do that in my own function? How would I be able to work with infinity arguments passed? How do they do it? func_get_args will do what you want: function infinite_parameters() { foreach (func_get_args() as $param) { echo "Param is $param" . PHP_EOL; } } You can also use func_get_arg to get a specific parameter (it's zero-indexed): function infinite_parameters() { echo func_get_arg(2); } But be

How to keep already-set GET parameter values on form submission?

故事扮演 提交于 2019-11-30 07:47:59
问题 I have a URL : foo.php?name=adam&lName=scott , and in foo.php I have a form which gives me values of rectangleLength & rectangleBreadth with a submit button. When I click this submit button with form action as $_SERVER['REQUEST_URI'] , I get this result URL: foo.php?rectangleLength=10&rectangleBreadth=5 (these values have been filled in by the user). Notice that I am losing my previous values name & lName from the URL. How can I keep them? Also, keep in mind that I have to come back to foo

passing vector to function c++

眉间皱痕 提交于 2019-11-30 07:35:09
I have a main.cpp test.h and test.cpp> I am trying to pass my vector through so i can use it in test.cpp but i keep getting errors. //file: main.cpp int main(){ vector <Item *> s; //loading my file and assign s[i]->name and s[i]-address tester(s); } //file: test.h #ifndef TEST_H #define TEST_H struct Item{ string name; string address; }; #endif //file: test.cpp int tester(Item *s[]){ for (i=0; i<s.sizeof();i++){ cout<< s[i]->name<<" "<< s[i]->address<<endl; } return 0; } ---------------errors-------- In file included from main.cpp:13: test.h:5: error: âstringâ does not name a type test.h:6:

Passing a Python list to php

两盒软妹~` 提交于 2019-11-30 07:23:34
I'm very new to php and I've been spending quite some type understanding how to pass arguments from Python to php and conversely. I now know how to pass single variables, but I am still stuck and can't seem to find an answer to this one: Php calls a Python script (that part works) that returns a list of strings. I'd like to process this list in php. When I try: print mylist in myscript.py, and then : $result = exec('python myscript.py') it looks like php understands $result as a single string (which I agree makes sense). I understand that maybe json can help or that I somehow need to use a

Where are python's splat operators * and ** valid?

北慕城南 提交于 2019-11-30 07:07:38
问题 The unpacking/splat operators * and ** differ widely in their applicability across python versions (2.7, 3.x < 3.5 and 3.x >= 3.5). For example: | 2.7 | 3.1-3.4 | 3.5 ---------------------------------------------------------------------- function(*args) ✓ ✓ ✓ x, *y, z = [1, 2, 3, 4, 5] x ✓ ✓ {**x, **y} x x ✓ Are there any more discrepancies between the various versions that I've missed? I'm looking through PEP and Readmes but the docs aren't detailed with this. 回答1: Around 1992 (not sure

Pass by reference, constant reference, rvalue-reference, or constant rvalue-reference?

谁说我不能喝 提交于 2019-11-30 06:56:02
I was learning passing by reference, and here is the test I did: #include <iostream> using namespace std; int i = 0; //If this is uncommented, compiler gives ambiguous definition error. //void paramCheck (string s) { // cout << ++i << ". Param is var.\n"; //} void paramCheck (const string& s) { cout << ++i << ". Param is const ref.\n"; } void paramCheck (string& s) { cout << ++i << ". Param is non-const ref.\n"; } void paramCheck (const string&& s) { cout << ++i << ". Param is const rvalue-reference.\n"; } void paramCheck (string&& s) { cout << ++i << ". Param is non-const rvalue-reference.\n"

Using an OrderedDict in **kwargs

谁说胖子不能爱 提交于 2019-11-30 05:48:03
Is it possible to pass an OrderedDict instance to a function which uses the **kwargs syntax and retain the ordering? What I'd like to do is : def I_crave_order(**kwargs): for k, v in kwargs.items(): print k, v example = OrderedDict([('first', 1), ('second', 2), ('third', -1)]) I_crave_order(**example) >> first 1 >> second 2 >> third -1 However the actual result is: >> second 2 >> third -1 >> first 1 ie, typical random dict ordering. I have other uses where setting the order explicitly is good, so I want to keep **kwargs and not just pass the OrderedDict as a regular argument abarnert As of

Optional parameters in Python functions and their default values [duplicate]

≯℡__Kan透↙ 提交于 2019-11-30 05:40:28
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I'm kind of confused about how optional parameters work in Python functions/methods. I have the following code block: >>> def F(a, b=[]): ... b.append(a) ... return b ... >>> F(0) [0] >>> F(1) [0, 1] >>> Why F(1) returns [0, 1] and not [1] ? I mean, what is happening inside ? Good doc from PyCon a couple years back - Default parameter values explained . But basically, since lists are mutable objects, and keyword arguments are evaluated at function definition time, every time you call the function, you get the same