Help for this page

Select Code to Download


  1. or download this
    my @array = qw(red blue green yellow black white purple brown orange g
    +ray);
    foreach (@array) {
        do_something_with($_);
    }
    
  2. or download this
    #  Inputs:  $1 ... color name
    #           $2 ... The color index (a new arg)
    ...
        # For now, just print the color prefixed with its index...
        printf " %2d.  '$color'\n", $idx;
    }
    
  3. or download this
    for (my $i = 0; $i < @array; $i++) {
        my $item  = $array[$i];
        do_something_with($item, $i);
    }
    
  4. or download this
    my $i;
    foreach (@array) {
        do_something_with($item, $i++);
    }
    
  5. or download this
    use feature ":5.10";
    my @array = qw(red blue green yellow black white purple brown orange g
    +ray);
    ...
    #  7.  'brown'
    #  8.  'orange'
    #  9.  'gray'
    
  6. or download this
    for (@array) {
        do_something_with($_, ++ state $i);
    ...
    #  8.  'brown'
    #  9.  'orange'
    # 10.  'gray'
    
  7. or download this
    map { do_something_with($_, state $i++) } @array;