next up previous contents
Next: Forward references Up: Variables Previous: Variable basics   Contents

Variable scoping

Scoping is similar to C: variables defined within curly braces are not visible beyond the closing brace. It is an error to try to access an undefined variable. Note that it is not possible to change the value of a variable defined at an outer scope - instead, a new variable at the inner scope is created.

Like in C or Perl, blocks can be created inside other blocks, which is mainly useful when writing macros.

Example:

prio {
    {
        $x = 1;
        class ($x);
    }
    {
        $x = 2;
        class ($x);
    }
}



Martin A. Brown 2003-11-06