function

How can I know that PowerShell function parameter is omitted

Consider such function: function Test($foo, $bar) { ... } We can call it: Test -foo $null Test How can I know when the -foo was omitted, and when it was $null? ...

How to omit $null arguments calling a function?

Consider such function: $missed = "{716C1AD7-0DA6-45e6-854E-4B466508EB96}" function Test($foo = $missed, $bar = $missed) { if(!$foo) { throw "error" } if(!$bar) { throw "error" } } I whould like to call this function this way Test -foo $foo -bar $bar But if $foo or $bar is $null, exception will be thrown. The ...

Matching Array and Function Syntax

So the idea behind an array and a function are very similar from a black-box perspective. You pass in the input value(s) and retrieve the output value. So is it better to keep array syntax and function syntax the same or is it better to have differences? e.g. print array[0] print func(0) versus print array(0) print f...

How can I export all subs in a Perl package?

I would like to expose all subs into my namespace without having to list them one at a time: @EXPORT = qw( firstsub secondsub third sub etc ); Using fully qualified names would require bunch of change to existing code so I'd rather not do that. Is there @EXPORT_ALL? I think documentation says it's a bad idea, but I'd like to do it a...

How would you go about designing a function for a perfect hash?

The domain of interest is string matching. Assume I have a structure like this. typedef struct { char *name, int (*function)(); } StringArray StringArray s[] = { {"George", func1}, {"Paul", func2}, {"Ringo", func3}, {"John", func4} } There are a fixed number of strings in the array. They are hard cod...

Template Specialization of Function inside of a Templated Class

I have a templated class and inside I have a templated function( different template parameters ) and I having issues getting the compiler to call the correct one. Example: template< class Parm1, class Parm2, class Parm3 > class Class { public: void Func( Parm1 arg1, Parm2 arg2 ) { Call<Parm3>( arg1, arg2 ); } protected:...

How to use php function without load source file ?

I would like to use my function, for example DebugR(), but I don't want to use a require or include (with include_path) to load the function file that contains the source. I know I could use an autoload, but this action must be generic in my php configuration. I think I must create a PHP extension, but is there another way? ...

Why won't my Perl function work?

I am having trouble with a function I wrote... sub TemplateReplace { my($regex, $replacement, $text) = @_; $text =~ s/($regex)/($replacement)/gs; } my $text = "This is a test."; TemplateReplace("test", "banana", $text); But it doesn't work. I thought arguments were sent by reference in Perl. Does the line my($regex, $replacem...

Programatically determining amount of parameters a function requires - Python

I was creating a simple command line utility and using a dictionary as a sort of case statement with key words linking to their apropriate function. The functions all have different amount of arguments required so currently to check if the user entered the correct amount of arguments needed for each function I placed the required amoun...

Returning an enum from a function in c?

If I have something like the following in a header file: enum Foo { BAR, BAZ }; how do I declare a function that returns an enum of type foo? Can I just do something like the following: Foo testFunc() { return Foo.BAR; } Or do I need to use typedefs or pointers or something? ...

PHP syntax for dereferencing function result

In every other programming language I use on a regular basis, it is simple to operate on the return value of a function without declaring a new variable to hold the function result. In PHP, however, this does not appear to be so simple: <?php function foobar(){ return preg_split('/\s+/', 'zero one two three four five'); } // can ...

Is it good to send stack allocated object as a pointer parameter to some other function?

Is it good to send stack allocated object as a pointer parameter to some other function? ...

Call external (i.e. interface) functions also internally?

I am wondering if it is good practice to call public functions also internally. By public functions I mean all methods/functions that you created explicitly to be called from other objects, modules, etc. For example methods that you would typically put in a Java interface definition. By calling internally, I mean in the same module, cl...

Passing an Array as Arguments, not an Array, in PHP

I seem to remember that in PHP there is a way to pass an array as a list of arguments for a function, dereferencing the array into the standard func($arg1, $arg2) manner. But now I'm lost on how to do it. I recall the manner of passing by reference, how to "glob" incoming parameters ... but not how to de-list the array into a list of a...

How can I return multiple values from a function in C#?

I read the C++ version of this question but didn't really understand it. Can someone please explain clearly if it can be done and how? Thanks, Ash ...

Join to table-valued function in MSSQL 2000?

I have a table with a whole name. I have a function that receives said name, parses it, and returns a table with first, middle, last, and suffix. I have a bad (edit: was "hyper-conservative") DBA who won't upgrade the dev server to the same version as the production one so I can't just use APPLY and be done with it: insert into blah (...

Templated namespaces and typedefs are illeagal -- workarounds?

I have a templated function fct that uses some complex data structure based on the template parameter. It also calls some helper functions (templated on the same type) that are in a separate helpers namespace and use the same complex data structure. Now it gets really ugly because we cannot make one typedef for the complex type that all ...

PHP function that creates a nested ul li?

Hello, I am attemptting to attach a small CMS to a website I am creating. However I have come across a small problem. The CMS uses PHP functions for inserting menus, these PHP functions create the HTML. The particular function I wish to use (treemenu) creates a nested ul li that can then be used for a drop down menu. However the nested ...

sql function to return table of names and values given a querystring

Anyone have a t-sql function that takes a querystring from a url and returns a table of name/value pairs? eg I have a value like this stored in my database: foo=bar;baz=qux;x=y and I want to produce a 2-column (key and val) table (with 3 rows in this example), like this: name | value ------------- foo | bar baz | qux x | ...

The difference between assigning event handlers with bind() and each() in jQuery?

Hi, can someone tell me what the difference between assigning event handlers using bind(): $(function(){ $('someElement') .bind('mouseover',function(e) { $(this).css({ //change color }); }) .bind('mouseout',function(e) { $(this).css({ //return to previous state }); ...