51

Variables
Assigning to List Variables

  • Parentheses () define a new list

      @foo = ( "apple", "bat", "cat" );

  • The scalar $ plus [] references one element (note: indexes start at 0)

      $foo[0] = "ape";

  • Creating and setting an element

      $foo[3] = "dog";

  • Assigning multiple element values

      $foo[1,3] = ( "bear", "dear" );

  • Adding new elements

      @foo = ( @foo, "elk" ); # Append
      @foo = ( "ace", @foo ); # Prepend