next up previous contents
Next: Variable scoping Up: Variables Previous: Variables   Contents

Variable basics

Like in Perl, variable names begin with a dollar sign, followed by a letter or an underscore, optionally followed by more letters, digits, or underscores.

Also like in Perl, variables can contain strings.


$five = 5;
$answer = ($five << 3)+2;
$rate = 135.5 Mbps;
$host = "";

If an expression stored in a variable is not constant, it is inserted ``as is'' wherever the variable is referenced. Note that any references to fields or other variables are resolved at the time of assignment.


$cond = ip_src == && tcp_sport == 80;
    class (1) if $cond;
field tcp_sport = ...;  // does not change $cond
    class (2) if $cond;

Martin A. Brown 2003-11-06