scope

How can I declare and use T-SQL variables across multiple SqlCommands using the same SqlConnection object to perform multiple inserts into a table variable?

I want to load a list of records given a possibly lengthy list of usernames (anywhere from one to thousands of usernames). Disregard how the name(s) are chosen, and assume they cannot be determined from any existing data in the database. This applies to SQL Server 2005. I specifically want to avoid using a single select statement with ...

NameError using execfile in python

My application has a button to execute a python script dynamically using execfile. If I define a function inside the script (eg. spam()) and try to use that function inside another function (eg. eggs()), I get this error: NameError: global name 'spam' is not defined What is the correct way to call the spam() function from within eggs...

Scope, using functions in current module

Hi, I know this must be a trivial question, but I've tried many different ways, and searched quie a bit for a solution, but how do I create and reference subfunctions in the current module? For example, I am writing a program to parse through a text file, and for each of the 300 different names in it, I want to assign to a category. T...

.NET instant out of scope notification?

In .NET, is there a simple way for a class to be notified as it falls out of scope? ...

How to properly work _around_ Javascript persistence?

There is basic persistence of Javascript vars/etc. You call a function/method, and the next time you call that same function/method, it is holding the data from the last time. You can delete the vars when you are done with them, but that removes the advantage of using the code again for that instance. So what is the proper way to write...

T-SQL Indexing Service SQL openquery optimization

Scenario: I am using a T-SQL stored proc (Sql Server Management Studio) to return search matches for text documents using the MS Indexing Service and this (simplified) query: SELECT * FROM openquery( filesystem2, 'SELECT Path, Rank, Filename FROM SCOPE('' "e:\test\documents" '') WHERE CONTAINS('' FORMSOF ...

Python function calls are bleeding scope, stateful, failing to initialize parameters?

Before I have the audacity to file a bug report, I thought I'd check my assumptions among wiser Pythonistas here. I encountered a baffling case today, so I whittled it down to a toy example, shown below: #!/usr/bin/env python # -*- coding: UTF-8 -*- """ A little script to demonstrate that a function won't re-initialize its list paramet...

(Ruby,Rails) Context of SELF in modules and libraries...?

Hi All, Quick question regarding the use of "SELF" inside a module or library. Basically what is the scope/context of "SELF" as it pertains to a module or library and how is it to be properly used? For an example of what I'm talking about, check out the "AuthenticatedSystem" module installed with "restful_authentication". Best NOTE:...

Javascript/Prototype scope confusion

I'm creating a JavaScript class (using Prototype) that will set the page state to idle if there's no mouse movement within a specified number of seconds. When the mouse moves, the class will "wake up" the page by sending a message to a list of listeners. The thing I don't understand is that this.handlers is valid in one function (setIdl...

Why are lexical scopes prefered by the compilers?

How does lexical scope help the compilers? Does it help in compilation or optimization? ...

Making a function only accessible from one other function

How can I declare and define a function so that it is only accessible from a single function? I can declare a function in another function. But since local function definitions are illegal (according to Visual C++) I must define the function at global scope, making it possible for other functions to call it. void f1() { void f1_priv...

Scoping rules when inheriting - C++

I was reading the C++0x FAQ by Stroustrup and got stuck with this code. Consider the following code struct A { void f(double) { std::cout << "in double" << std::endl; } }; struct B : A { void f(int) { std::cout << "in int" << std::endl; } }; int main() { A a; a.f(10.10); // as expected, A.f will...

Finite questions

Are there a finite number of questions that can be asked regarding a specific language (and or topic), for example - for T-SQL given that there are only so many commands, can there be a limited number of non-repetitive questions? and if so can you use that to determine sizing for a site like stackoverflow and to determine the probability...

How can I replace (wrap) methods in new methods programmatically?

I have several methods that I need to wrap in new methods in basically the same manner. My first solution doesn't work, and I understand why, but I don't know if there is a simple solution to this problem or if it can't be done the way that I want to do it. Here's an example. I have objects a-c that have an onClick method. I need to exe...

jQuery javascript scoping problem

I have a hidden input element that I am using as a counter to use to name more input elements generated by JavaScript. To get the value of the counter i use parseInt($('#counter').val()); However I use this code snippet several times in my code, so I thought it would be good to put it in a function function getCounter(){ parseInt...

In C, how do I restrict the scope of a global variable to the file in which it's declared?

I'm new to C. I have a book in front of me that explains C's "file scope", including sample code. But the code only declares and initializes a file scoped variable - it doesn't verify the variable's scope by, say, trying to access it in an illegal way. So! In the spirit of science, I constructed an experiment. File bar.c: static char f...

Constricting find conditions based upon runtime contexts

Wow crazy title! But here's the problem. In efforts to dry up my school website management system application, I've made a module of my application (FileSet) restful and placed it in one place. Previously FileSet was used in the general website system, and also in a kids learning area system. They both behaved exactly the same except for...

What is the scope of $1 through $9 in Perl?

What is the scope of $1 through $9 in Perl? For instance, in this code: sub bla { my $x = shift; $x =~ s/(\d*)/$1 $1/; return $x; } my $y; # some code that manipulates $y $y =~ /(\w*)\s+(\w*)/; my $z = &bla($2); my $w = $1; print "$1 $2\n"; What will $1 be? Will it be the first \w* from $x or the first \d* from ...

A tricky javascript question

I'll probably best explain this through code. I got something like this: var object1 = function(){ //do something } var object2 = function(){ //do something else } var objects = { 'o1' : object1, 'o2' : object2 }; var actions = []; function addAction( actionName ){ var object = objects[actionName]; actions.push( functio...

Setting the scope on a model for the rest of a request

I'm wondering if there is a way to set a scope on a model class for the rest of a request? I.e. I want to scope down some results, but I want to do it without the main restful controller knowing (perhaps in a before_filter injected into the controller). Contacts.scope = { :conditions => {:public => true} } if ladeda then later on Con...