scope

++ Operator on Variable Is Not Changing As Expected In ScriptBlock

99封情书 提交于 2019-12-12 08:58:13
问题 I am trying to rename files by putting a prefix based on an incrementing counter in the files such as: $directory = 'C:\Temp' [int] $count=71; gci $directory | sort -Property LastWriteTime | ` rename-item -newname {"{0}_{1}" -f $count++, $_.Name} -whatif Yet all the files processed are 71_ and $count in $count++ never increments and the filenames are prefixed the same? Why? 回答1: The reason you cannot just use $count++ in your script block in order to increment the sequence number directly is:

In cmd.exe, how can you get one variable to escape the setlocal command?

岁酱吖の 提交于 2019-12-12 08:36:47
问题 I frequently find myself using setlocal within cmd.exe to avoid polluting the environment variable space with temporary variables (and to ensure both command extensions and delayed expansion are active). However, I'm at a loss on how to do this if I actually want one of those variables to be made available. Consider the following code which gives you the final component of the current directory (so c:\pax\dir1 would give you dir1 ): @echo off :main setlocal enableextensions

Access dynamic $scope variable inside html

£可爱£侵袭症+ 提交于 2019-12-12 08:28:58
问题 I'm creating a large amount of directives and all will include dynamic scope variables that will be initialised inside the link functions e.g: // link: function(scope, ele, attr){ scope.key = scope.somevar + 'something_else'; scope[scope.key] = 'the_value'; } // I want to access the value in the templates of the directives via scope.key . <div ng-if="scope[key]"> something </div> Currently I only see it been viable through a function call like so: html <div ng-if="scope(key)"> something </div

JSF application scope instantiation and injection

落花浮王杯 提交于 2019-12-12 08:26:07
问题 Probably my question is a trivial one, but I never used an application scope bean before. I need the application bean because I have to do time consuming transactions on the database. my search didn't satisfy my curiosity at all. I don't know why but I didn't manage to initialize the bean (it is null) or it the app crashed. So I have an application scope bean @ManagedBean(eager=true) @ApplicationScoped public class ApplicationContainer { ... } eager=true I read that tells JSF to initiate the

Variable scope in nested functions

孤街醉人 提交于 2019-12-12 08:12:42
问题 Could someone explain why the following program fails: def g(f): for _ in range(10): f() def main(): x = 10 def f(): print x x = x + 1 g(f) if __name__ == '__main__': main() with the message: Traceback (most recent call last): File "a.py", line 13, in <module> main() File "a.py", line 10, in main g(f) File "a.py", line 3, in g f() File "a.py", line 8, in f print x UnboundLocalError: local variable 'x' referenced before assignment But if I simply change the variable x to an array, it works:

C++ Using a reference to the variable being defined

筅森魡賤 提交于 2019-12-12 08:06:14
问题 Is the following code valid C++, according to the standard (discounting the ...s)? bool f(T& r) { if(...) { r = ...; return true; } return false; } T x = (f(x) ? x : T()); It is known to compile in the GCC versions this project uses (4.1.2 and 3.2.3... don't even get me started...), but should it? Edit : I added some details, for example as to how f() conceptually looks like in the original code. Basically, it's meant to be initialize x in certain conditions. 回答1: Syntactically it is, however

Objective C - XCode not recognizing variable outside of if statement

杀马特。学长 韩版系。学妹 提交于 2019-12-12 07:27:41
问题 Trying to set a sprite filename with an if statement, then load the proper file based on that string. It looks like there's a problem with my variable scope, but I don't know what it is. Here's my code: if ([[GameManager sharedGameManager] newHighScore] == TRUE) { NSString *highScoreLabelText = @"label-new-high-score.png" } else { NSString *highScoreLabelText = @"label-high-score.png" } CCSprite *highScoreLabel = [CCSprite spriteWithSpriteFrameName:highScoreLabelText]; [highScoreLabel

how do I setInterval to call a function within a class

故事扮演 提交于 2019-12-12 07:18:51
问题 I have a class like: function run(){ this.interval; this.start = function(){ this.interval = setInterval('this.draw()',1000); }; this.draw = function(){ //some code };} var run = new run(); run.start(); however I can't seem to reference/call this.draw() within the setInterval, it says this.draw() is not a function, and if I remove the quotes it says useless setInterval call, what am I doing wrong? 回答1: The value of this is set depending on how a function is called. When you call a function as

How does scoping in Matlab work?

瘦欲@ 提交于 2019-12-12 07:17:22
问题 I just discovered (to my surprise) that calling the following function function foo() if false fprintf = 1; else % do nothing end fprintf('test') gives and error Undefined function or variable "fprintf" . My conclusion is that the scope of variables is determined before runtime (in my limited understanding how interpretation of computer languages and specifically Matlab works). Can anyone give me some background information on this? Edit Another interesting thing I forgot to mention above is

Symfony2 Service with an unique instance

℡╲_俬逩灬. 提交于 2019-12-12 06:39:23
问题 Please i need some help: I have the following services: SERVICE CONFIGURATION IN services.yml services: xpad.producto_repository: class: Xpad\ProductoBundle\Entity\ProductRepository factory_service: doctrine.orm.clientes_entity_manager factory_method: getRepository arguments: - Xpad\ProductoBundle\Entity\Product backend_cliente.producto_filters: class: Xpad\BackendClienteBundle\Filters\ProductFilters calls: - [setRepository, ["@xpad.producto_repository="]] scope: container AND THE CLASS FOR