VCL unset global variable - varnish

Is it possible to unset vcl global variable or clear the same
Example:
To set global variable
var.global_set("key", "value");
To unset the same
var.global_set("key", "");
Any possible way to actually unset it rather than assigning to an empty string?
Or any way to completely clear it?
Thanks

Related

Scope issue in TCL list

I am having a list globally declared.
global triaAXCord
set triAXCord {}
a procedure setCordinates appending values to this list.
proc setCordinates {AX} {
lappend triAXCord $AX
puts "$triAXCord"
}
that puts gives the value inserted.
But from other procedures when $triAXCord is printed as blank list. Since the list is globally declared why the values are not getting updated.
Outside of the proc definition, your triAXCord variable is already at the global scope. No need to explicity declare it as belonging to the global scope.
Within the proc, you are in the proc's scope and cannot access the global scope's variable unless you make it explicit within the proc. That's different than Python where functions can access global variables by default.
Either of these two methods works within the proc:
global triAXCord. This allows you to use triAXCord as a variable name in the proc.
Use the :: prefix before the variable name, like lappend ::triAXCord $AX.
You could also use upvar if you need more flexibility in variable names or scopes.

What is the different between Empty String and none Created Variable

What is the different between Empty String and none Created Variable in Batch File?
and if they have any different, can you show me an example of using empty string vs none created string?
#echo off
title Empty String Vs None Created Variable
set String=
set variable=exist
if [%String%] == [] echo its be a Empty String
if [%variable%] == [] echo its be a Empty String
if [%none_exist_var%] == [] echo its be a Empty String
Thanks a Lot!
Variables in batch files can be
Defined: there is a value stored and a associated name used to retrieve the value, that is, the variable name.
Undefined: there is no value and in consecuence there is not any need for an associated name, so it does not exist.
This two simple rules handle how the environment block (where variables/value are stored) is updated. If there is a value, the environment block has an entry for the value and the name to retrieve it. Without a value, the environment block does not create the entry or, when setting the variable to nothing, the entry is removed.
So, if
a never defined variable has not any entry in the environment block
a variable with not value has not any entry in the environment block
there is not any difference between the two cases.
note: While the traditional way to check if a variable stores a value / a variable exists is (as dbenham has commented, this syntax is not recommeded as quotes inside the variable value lead to syntax problems)
if "%varName%"=="" ....
if command extensions are enabled (and the default configuration is to have them enabled) you can also use a safer alternative
if not defined varName ....
if defined varName ....
note that in this syntax, as we are not trying to read the value in the variable, varName is used, not %varName%
There is no difference. Read Delete a variable:
Type SET with just the variable name and an equals sign:
SET _department=
Better still, to be sure there is no trailing space after the = place
the expression in parentheses or quotes:
(SET _department=)
or
SET "_department="

Using variables with susy-breakpoint in susy 2

I have recently upgraded to Susy2 and having to rework my base templates with new susy-breakpoints instead of at-breakpoint.
With the new susy-breakpoint I need to define a breakpoint and a layout for the short hand like so "60em, 12" and I have tried storing this in a variable e.g. "$large" so that I can pass it into various classes.
However as it is a single variable the mixin only sees it as one value so I can only store one value. Is there a way two store both values in a variable?
Yep. Sass has Variable Arguments which are great for handling this situation:
#include susy-breakpoint($large...) {
// Your code here
}
The ... does the magic.

Remove headers from vcl_deliver using regex

Is it possible to remove headers in vcl_deliver whose name matches a certain regular expression?
We throw headers called "X-env-blah" where "blah" could contain any value, and want them to be removed from the front-end.
Example (doesn't work):
unset resp.http.x-env$;
Or is there a way to loop through all the headers in vcl_deliver?
Thanks
VCL is a simple language that is converted into machine code when loaded.
There are no loops nor any globbing.
To do this you will either have to write a VMOD/inline-C, or just unset all possible headers each time.
Yes, but you need to install the vmod header. See: livmod-herader page at github.

append value to environment variable on builder call

The problem is as follows:
I have an environment with some variables defined like this:
env = Environment(CPPPATH=['#/include'])
In some cases I need to invoke a builder with some extra values which should not be added permanently to the environment to not unnecessarily pollute it.
One way is to append the extra value to the builder call by merging it with the environment's value.
env.Object('test.c', CPPPATH=['#/some_other_include_path']+env['CPPPATH'])
Is there a more elegant way to do it?
I do this by cloning the env and appending on to it, like this:
clonedEnv = env.Clone()
clonedEnv.Append(CPPPATH=['#anotherPath'])
clonedEnv.Object('test.c')
A more pythonic (and efficient) way to do what you are doing would be to use the python list.extend() function:
cpppath = ['path1', 'path2']
cpppath.extend(env['CPPPATH'])
env.Object('test.c', CPPPATH = cpppath)

Resources