variables

Defining common variables across multiple scripts?

那年仲夏 提交于 2020-01-21 08:50:30
问题 I have a number of Bash and Perl scripts which are unrelated in functionality, but are related in that they work within the same project. The fact that they work in the same project means that I commonly specify the same directories, the same project specific commands, the same keywords at the top of every script. Currently, this has not bitten me, but I understand that it would be easier to have all of these values in one place, then if something changes I can change a value once and have

how do I assign content from readfile() into a variable?

ε祈祈猫儿з 提交于 2020-01-21 08:03:21
问题 readfile() says it outputs the content but I want the content to be saved in a variable. How do I do that? I tried $content=readfile("file.txt") but that doesn't come out right. I want to do like this: $data=readfile("text.txt"); echo htmlentities($data); That should give you an idea of how I want that to work. 回答1: That is what file_get_contents is for: $data = file_get_contents("text.txt"); echo htmlentities($data); If you must use readfile you can use output buffering to get the contents

how do I assign content from readfile() into a variable?

感情迁移 提交于 2020-01-21 08:03:11
问题 readfile() says it outputs the content but I want the content to be saved in a variable. How do I do that? I tried $content=readfile("file.txt") but that doesn't come out right. I want to do like this: $data=readfile("text.txt"); echo htmlentities($data); That should give you an idea of how I want that to work. 回答1: That is what file_get_contents is for: $data = file_get_contents("text.txt"); echo htmlentities($data); If you must use readfile you can use output buffering to get the contents

Difference between static and const variables [duplicate]

北战南征 提交于 2020-01-21 06:34:28
问题 This question already has answers here : What is the difference between Const and Static in C#? (5 answers) Closed 4 years ago . what is the difference between "static" and "const" when it comes to declare global variables; namespace General { public static class Globals { public const double GMinimum = 1e-1; public const double GMaximum = 1e+1; } } which one is better (considering that these variables wont be changing ever) namespace General { public static class Globals { public static

How to convert string to variable-name in scheme

落花浮王杯 提交于 2020-01-21 05:26:10
问题 How can I achieve below in Scheme REPL? Create a variable name from a string. =>(define (string->variable-name "foo") 12) =>foo 12 =>(+ foo 8) 20 In Common Lisp, this should be => (set (intern "ANY-TEXT") 5) => ANY-TEXT 5 How do I build a #procedure like "string->variable-name" (and "variable-name->string") ? Thanks a lot. 回答1: If what you're passing to string->variable-name is always a string literal (i.e., not a variable that contains a string), you can do that using a syntax-case macro

refer to range of columns by name in R

前提是你 提交于 2020-01-21 03:35:26
问题 I need help with something that might be fairly simple in R. I want to refer to a range of columns in a data frame (e.g., extracting a few select variables). However, I don't know their column numbers. Normally, if I wanted to extract columns 4-10 i would say mydata[,4:10]. However, given that I don't know the column numbers, I would want to refer to them by name. Is there an easy way to do this? in sas or spss it is fairly easy to refer to a range of variables by name. Alternatively, is

How to pass a Bash variable to Python?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-20 04:52:07
问题 Eventually I understand this and it works. bash script: #!/bin/bash #$ -V #$ -cwd #$ -o $HOME/sge_jobs_output/$JOB_ID.out -j y #$ -S /bin/bash #$ -l mem_free=4G c=$SGE_TASK_ID cd /home/xxx/scratch/test/ FILENAME=`head -$c testlist|tail -1` python testpython.py $FILENAME python script: #!/bin/python import sys,os path='/home/xxx/scratch/test/' name1=sys.argv[1] job_id=os.path.join(path+name1) f=open(job_id,'r').readlines() print f[1] thx 回答1: Exported bash variables are actually environment

PHP - replace a string with a variable named like the string

那年仲夏 提交于 2020-01-19 10:06:34
问题 so the string is like this: "bla bla bla {VARIABLE} bla bla" when I use this string somewhere in a function I want to replace {VARIABLE} with $variable (or any other uppercase strings with wrapped within {} charcters). $variable (and any other variables) will be defined inside that function Can i do this? 回答1: $TEST = 'one'; $THING = 'two'; $str = "this is {TEST} a {THING} to test"; $result = preg_replace('/\{([A-Z]+)\}/e', "$$1", $str); 回答2: Use a regular expression to find all substitutions

Java local vs instance variable access speed

僤鯓⒐⒋嵵緔 提交于 2020-01-18 04:58:44
问题 So my question is about variable accessing speed in Java. Today in my "CS" (if you can call it that) the teacher presented a similar example to the following of a List: public class ListExample<T> { private Node<T> head; private Node<T> tail; private class Node<T> { /* ... */ } public void append(T content) { if (!isEmpty()) { Node<T> dummy = new Node<T>(content); head = dummy; tail = dummy; head.setNext(head); // or this dummy.setNext(dummy); } else { /* ... */ } } // more methods // ... }

Java local vs instance variable access speed

大憨熊 提交于 2020-01-18 04:58:24
问题 So my question is about variable accessing speed in Java. Today in my "CS" (if you can call it that) the teacher presented a similar example to the following of a List: public class ListExample<T> { private Node<T> head; private Node<T> tail; private class Node<T> { /* ... */ } public void append(T content) { if (!isEmpty()) { Node<T> dummy = new Node<T>(content); head = dummy; tail = dummy; head.setNext(head); // or this dummy.setNext(dummy); } else { /* ... */ } } // more methods // ... }