Lists and Arrays



Lists



Creating Lists



Lists and Arrays



Arrays have Value Semantics



Printing Lists with Join



Foreach loop: More printing lists



Lists and Parentheses



Right and Left Precedence



The Empty List



Lists Within Lists



Lists Assignment



Splitting a String to Create a List



List/Array Indexing



List Operators



Output Field and Record Separators





Arrays as Stacks and Queues

  • Stack ops: push, pop


  • Context

    CONTEXT: determines how some expressions are evaluated
    
          - Two contexts: list and scalar
    
          - Example:
                @a = (5,6,7,8);
                
                $x = @a;    # @a is evaluated in scalar context
                @y = @a;    # @a is evaluated in list   context
    
                print $x;   # Prints 4, the length of the array @a
                print @y;   # Prints 5678, the elements of @a
    
          - Context affects: 
              - a variable - how it is interpreted, 
    
    	  - function results - how they are interpreted
    
    	  - operators - what returned
    
          - Context is set by: 
              - LHS of assignment sets the context for the RHS, 
    
    	  - what function expects sets the context for its parameters
    
    	  - boolean expression - never cause any conversions
              - subroutines can return different things in different contexts 
    
            - print scalar reverse $line