variables

is there a way to access a non-global shadowed variable in javascript

主宰稳场 提交于 2020-01-11 10:41:09
问题 I'm currently learning javascript scope and was just wondering whether it is possible to access a non-global shadowed variable in javascript? i.e. in the example below, the variable a that equal to 10 in the aFunc function var a = 1; function aFunc(){ var a = 10; function innerFunc(){ var a = 100; console.log("innerFunc a = " + a); console.log("is it possible to access outer function's a variable?"); console.log("global a = " + window.a); } innerFunc(); } aFunc(); ps - I understand naming

In Ruby is it possible to create a local variable explicitly

寵の児 提交于 2020-01-11 10:17:33
问题 e.g. x = 123 p = Proc.new { x = 'I do not want change the value of the outer x, I want to create a local x' } In Ruby Is there something the same as "my" keyword in Perl ? 回答1: As per the Perl documentation of my,I think you are looking for something like below in Ruby:- x = 123 p = Proc.new {|;x| x = 'I do not want change the value of the outer x, I want to create a local x' } p.call # => "I do not want change the value of the outer x, I want to create a local x" x # => 123 回答2: Beware!

How to redirect grep output to a variable?

怎甘沉沦 提交于 2020-01-11 09:30:11
问题 I have some pipe. For example, I have this pipe: user@user:~$ cal | head -1 | grep -oP "[A-Za-z]+" For this pipe I get this result: September I want to store this result to a variable. I write the following commands: user@user:~$ cal | head -1 | month=$(grep -oP "[A-Za-z]+") | echo $month And I get the blank string. What is the problem? 回答1: month=$(cal | head -1 | grep -oP "[A-Za-z]+") or month=$(date +%B) 来源: https://stackoverflow.com/questions/25710640/how-to-redirect-grep-output-to-a

A way to dynamically create variables in Matlab?

柔情痞子 提交于 2020-01-11 07:25:35
问题 The case I am working on is dividing a big three-dimensional array of data that I have collected using good coding practises (etc...) and now I need to segment the layers of this array into separate variables for individual processing elsewhere, I can't call my data like this BigData(:,:,n) . So I would like to create a loop where I create new variables like so for i=1:n createVariable('user_' i) = BigData(:,:,i); end How do I do this without writing n new variables by hand every time? user_1

“bad variable name” using “read var”

Deadly 提交于 2020-01-11 06:07:07
问题 I am getting confused about Linux shells. It may be that I oversee something obvious as a Linux noob. All I want is the following script to run: #!/bin/bash echo "Type some Text:" read var echo "You entered: "$var Here is the situation: Installed Ubuntu Server 14.04 in a VirtualBox on windows Installed it with this packages A SAMBA mounted on /media/buff The script is on /media/buff/ShellScript/test.sh made executable by "sudo chmod a+x /media/buff/ShellScript/test.sh" The rest is default I

“bad variable name” using “read var”

不想你离开。 提交于 2020-01-11 06:04:11
问题 I am getting confused about Linux shells. It may be that I oversee something obvious as a Linux noob. All I want is the following script to run: #!/bin/bash echo "Type some Text:" read var echo "You entered: "$var Here is the situation: Installed Ubuntu Server 14.04 in a VirtualBox on windows Installed it with this packages A SAMBA mounted on /media/buff The script is on /media/buff/ShellScript/test.sh made executable by "sudo chmod a+x /media/buff/ShellScript/test.sh" The rest is default I

“variable declared and not used” compilation error

怎甘沉沦 提交于 2020-01-11 05:07:06
问题 I am learning Google's new language Go. I am just trying stuff out and I noticed that if you declare a variable and do not do anything with it the go compiler ( 8g in my case) fails to compile with this error: hello.go:9: error declared and not used . I was suprised at this since most language compilers just warn you about unused variables but still compile. Is there anyway I can get around this? I checked the documentation for the compiler and I don't see anything that would change this

How to list all PHP variables in a file?

▼魔方 西西 提交于 2020-01-11 04:16:28
问题 I have a PHP file with PHP Variables inside. Example: Hi <?=$username?>, Can you please send me an email ? I would like to list from an outside file, every PHP variables in this file. Something that would return: Array( 'username' ); I know there is a PHP function called get_defined_vars , but this is an external file. Is there a way to get all PHP vars from an external file ? Thank you 回答1: Use file_get_contents() and preg_match_all() : $file = file_get_contents('file.php'); preg_match_all('

Update Jmeter variables with beanshell

陌路散爱 提交于 2020-01-11 04:06:06
问题 I've encountered a problem when trying to update a Jmeter variable with a beanshell script. I've followed this manual and i have seen this topic and both say the same: To update a variable use vars.put("variable", "newValue"); The value that you put can only be a String. Now I want to use this code: String x = vars.get("counter"); int y = Integer.parseInt(x); y = y + 1; String z = "" + y; vars.put("counter", z); // print(z); My variable counter is a user parameter (tried before as user

PHP undefined variable mysqli connection

瘦欲@ 提交于 2020-01-11 03:30:07
问题 I have a mysql connection which is included in a separate file: require 'settings.php'; and I have a file with all functions, also included: require 'functions.php'; In the settings there it looks like this: $db = mysqli_connect("host", "username", "passwort", "database"); if(!$db) { exit("Error: ".mysqli_connect_error()); } and a function uses this connection like this: function includehomepage() { $data = array(); $query = "SELECT pagecontent FROM `pages` WHERE `id` = `0`"; $query = mysqli