How I can store the {{$time stamp}} variable in global varibale - variables

On the end point I need to generate a number (for phone number) Thats why I used {{$timestamp}} in environment variable.
Is there any way I can store that same Timestamp in global varibale?

you can use postman.setGlobalVariable() function to set the global variable and postman.getGlobalVariable() function to retrieve the value.
In your case, it should be:
postman.setGlobalVariable("timeStamp", [value]);
postman.getGlobalVariable("timeStamp");
or simply {{timeStamp}}

Related

Lua: check local or global variable

Is there a way to check if variable is global or local? I mean to do it using programming facilities, not by reading a code?
For example
print(type(a))=>"number",
print(checklocal(a))=>true
Variables are local in certain scope. Yes, you can access the local variables of any active function by calling debug.getlocal(StackLevel, Index), it returns two values:
Name of the variable
Value of the variable
-- Example
local isGlobal = 99
function testFunc(var)
local v1, v2, v3 = 1, 2, 3
local a = 1
while true do
local name, value = debug.getlocal(1, a)
if not name then break end
print(name, value)
a = a + 1
end
end
testFunc('xyz')
-- Result
-- var xyz
-- v1 1
-- v2 2
-- v3 3
-- a 5
local isGlobal = 99 is outside of the scope of our testFunc() hence getlocal will not print it, whereas all other variables within scope of our testFunc are printed with their values.
The locality of any given variable can be always determined from the source, so if you program in pure Lua, I can't see any purpose of this. I suppose it might be useful in cases where you do some preprocessing perhaps, so here is one way of doing it, without having to depend on the name:
local variable
print(debug.getupvalue(function()variable()end, 1) ~= "_ENV")
function()variable()end will, for a local variable, capture it as an upvalue (debug.getupvalue will return "variable"). If variable gets resolved to a global variable instead, the function has to store the global environment, _ENV, as an upvalue instead (which gets indexed with the name of the variable). There is no need to call variable in the function, this is just the shortest way to "use" it. If variable is _ENV, it always prints false (even though _ENV is always local).
Another option, which works correctly for _ENV:
local variable
print(debug.getupvalue(function()_ENV(variable)end, 2) ~= nil)
function()_ENV(variable)end always captures _ENV, and variable as well, if it is local, so checking the second index determines whether the variable was local or not.
This works from Lua 5.2 onwards.
For a solution without using the debug library, you can temporarily set the __newindex metamethod on _ENV, assign some values around, and check if the metamethod gets called.

What are anonymous variables?

A program variable is an abstraction of a computer memory cell or collection
of cells. Programmers often think of variable names as names for memory locations, but there is much more to a variable than just a name.
In this case, what is an anonymous variable?
What does the below statement mean?
Variables without names are called anonymous variables.
Can you provide language specific examples for the same?
In C++, reference variable to const can be initialized by constant.
In this point, temporary variable is created in memory to grab the constant.
const int &ref = 3;
like this. so we can call this temporary variable to "anonymous variable".
Variables are where you store you values. 'Variable Name' is the usually the easiest (and more human-like) way to locate your value.For example, if I am a variable, you can get my value by calling my name, and the combination of my value and my name is called 'variable'.
However, not all variables need a name.Sometimes you just use them once and don't need them anymore; and in that case, a name is unnecessary.
The example given by #BAE HA RAM is a telling one,in which case you don't need a name for the value but ref to it by a pointer(But still got a name for that pointer)..
There are also many other anonymous things, anonymous type, anonymous function and so on. Most of them are created to avoid too many meaningless names for the things that you only need to run once.
I'd like to know which language you are using, so more specific example can be given...

Specman: how to access a variable in a sequence?

I have a variable in my Specman sequence that i am using as a flag. I would like to check that flag after the sequence is called. Is there a way to access that varible in the MAIN function after the sequence has updated its value?
Thanks

Is there a way to change the values of variables in this language?

I am writing a procedure in scheme and I am trying to manipulate the values of variables. I use the define function to give a value to a variable but I can't change the value. I would have used the let function but the variable change is only effective in the body of the let function. Are there other ways to manipulate variabes and be able to view the changes from anywhere in the procedure?
Thanks
you can use set! set-car! set-cdr! after the variable has been defined

return type of who_user in scilab

I work with scilab, but during a project, scilab has to deal with a large number of variables.
I was wondering if i can do the following
var_list = who_user();
for _var_ = var_list do
if _var_ is global then
writetofile(human_readablefile, _var_)
end
end
clear()
of course this is a pseudocode, and i have a few questions before i implement it.
I can not get var_list = who_user() working. so i believe the function does not return anything. I am reluctant to hack into the code of the "who_user" macro itself. Is there any other way to get the list of user variables in another variable?
Is there a way to find the global variables out of them?
If not, then what are some memory management techniques in scilab?
I am able to answer your first query:
From a slight modification of the who_user function itself:
function nams = who_user1()
//get user variables
[nams,mem]=who('get'); //get all variables
p=predef(); //number of system variable
st=stacksize()
nams=nams(1:$-p+1);mem=mem(1:$-p+1);
//modifiable system variables
excluded=['demolist','scicos_pal','%scicos_menu',..
'%scicos_short','%helps','%helps_modules','MSDOS','who_user','%scicos_display_mode', ...
'%scicos_help'];
ke=grep(nams,excluded)
nams(ke)=[];mem(ke)=[];
n=size(nams,1);
if n==0 then return,end
//format names on n*10 characters
ll=length(nams)+2;m=int((ll-1)/10)+1;
for k=1:max(m)
ks=find(m==k);
if ks<>[] then nams(ks)=part(nams(ks),1:(k*10));end
end
endfunction
This function should give you the list you desire (I have modified the name to who_user1).
You can find out whether a specific variable is global or not by using the isglobal() function, but you need to pass a variable to isglobal(), not the string that is the name of the variable. The function I've listed above returns a vector of strings.
An alternative approach you could try would be to rewrite the above function to return the variables (rather than their names) directly using varargout and then testing them for being globals.