New

From CacheWiki
Jump to: navigation, search

The New command controls variable scoping.

By default all variables in Cache have global scope.

A variable can be newed within a block of code and this creates a new instance of the variable with scope that includes the current block and all blocks called from the current block. This is a similar scoping rule to the Perl local command.

Variables in Procedure blocks have different scoping rules. All variables referenced within a procedure block are local to that block and not visible or accessible from any other block. In Perl terms a variable in a procedure block is automatically a my variable.

There is, however, one exception. Variables with names that begin with % have global scope within procedure blocks. They can still, however, be newed, to give them local scope within a regular block.

Personal tools