80

Flow Control
FOREACH Loop Feature

  • If a solitary list is used then the loop control variable REFERENCES each value

  • Modifying the loop control variable modifies the list values!
      @foo = ( "ape", "bat", "cat" );
      foreach $animal ( @foo )
      {
      	$animal .= "-like";
      }
      
  • Avoiding modification
      @foo = ( "ape", "bat", "cat" );
      foreach $animal ( @foo )
      {
      	$a = $animal;
      	$a .= "-like";
      }