Help for this page

Select Code to Download


  1. or download this
    my @stuff = 0 .. 9;
    for my $ix ( 0 .. $#stuff ){
      my $item = $stuff[$ix];
      my $prev = $stuff[$ix-1];
      my $next = $stuff[$ix+1];
    }
    
  2. or download this
    my @stuff = 0 .. 9;
    my $lastitem = "";
    for my $item ( @stuff ){
    ...
      }
      $lastitem = $item;
    }
    
  3. or download this
    my @stuff = 0 .. 9;
    my @lastitem ;
    for my $item ( @stuff ){
    ...
      push @lastitem, $item;
      shift @lastitem while 3 == @lastitem; ### keep at most 3 last items
    }