- Variable names can start with a letter, a number, or an underscore, although they normally begin with a letter and can then be composed of any combination of letters, numbers, and the underscore character.
- Variables can start with a number, but they must be entirely composed of that number; for example, $123 is valid, but $1var is not.
- Variable names that start with anything other than a letter, digit, or underscore are generally reserved for special use by Perl
- Variable names are case sensitive; $foo, $FOO, and $fOo are all separate variables as far as Perl is concerned.
- As an unwritten (and therefore unenforced) rule, names all in uppercase are constants.
- All scalar values start with $, including those accessed from an array of hash,for example $array[0] or $hash{key}.
- All array values start with @, including arrays or hashes accessed in slices,for example @array[3..5,7,9] or @hash{‘bob’, ‘alice’}.
- Namespaces are separate for each variable type—the variables $var, @var, and %var are all different variables in their own right.FUNDAMENTALS In situations where a variable name might get confused with other data (such as when embedded within a string), you can use braces to quote the name. For example, ${name}, or %{hash}.
- Limited to 255 characters, however. We hope that suffices
Monday, March 16, 2009
Basic Naming Rules in Perl
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment