Variables
 
Naming
  • Variables are a letter, followed by zero or more letters, digits or underscores
     
  • Case-sensitive
     
  • All characters are significant
     
  • Sign defines type of variable:
    $scalar
    @list
    %hash
Interpolation
  • Strings inside of doublequotes are expanded out
    print "There were $nmatches matches found.";
    is the same as
    print "There were ", $nmatches, " matches found.";
     
  • Quoting the dollar sign removes significance:
    my $n=5; print "The value of \$n is $n";
    gives
    The value of $n is 5
Scope
  • By default, variables are global.
     
  • local $var hides & saves a copy of $var for the duration of the block.
     
  • my $var is probably what you want for "local variables" as we understand them from C and other languages.
Index
Introduction
What Is Perl?
Perl Resources
Running a Perl Program
Perl Thinking
Data Types
Scalars
Strings: Single Quoted
Strings: Double Quoted
Scalar operations
Scalar comparisons
Variables
Lists
Using Lists
Control Structures
Hashes
Hash Manipulation
File Handling
Regex Matching
Regex Matching: Ex. 1
Regex Matching: Ex. 2
Regex Replacing
Subroutines
Anonymous subs
References
Structures
Modules
Modules: File::Find
Modules: Internet
Modules: Win32::*
Everything Else
  Next page >>>