Scalar comparisons
 
Comparison operators
  • Two different types of operators: string and numeric
     
  • Perl decides based on context
     
  • The ones with letters are for strings. The ones without letters are for numbers.
Comparison operators
Comparison Numeric String
Equal == eq
Not equal != ne
Less than < lt
Greater than > gt
Less than or equal to <= le
Greater than or equal to >= ge
Three-way compare <=> cmp


 

  • Make sure you're comparing your strings and numbers appropriately.
     
  • 7 < 30 is true
    "7" lt "30" is false
  • 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 >>>