local

Usage

local $id = xpath

local %id = xpath

local $id|%id [ $id|%id ... ]

Description

This command acts in a very similar way as assign does, except that the variable assignment is done temporarily and lasts only for the rest of the nearest enclosing command-block. At the end of the enclosing block or subroutine the original value is restored. This command may also be used without the assignment part and assignments may be done later using the usual assign command.

Note, that the variable itself is not lexically is still global in the sense that it is still visible to any subroutine called subsequently from within the same block. A local just gives temporary values to global (meaning package) variables. Unlike Perl's my declarations it does not create a local variable. This is known as dynamic scoping. Lexical scoping is not implemented in XSH.

To sum up for Perl programmers: local in XSH works exactly the same as local in Perl.

See Also

assign, def