Help for this page

Select Code to Download


  1. or download this
    for my $x (1,2) {
      $x++;
    }
    
  2. or download this
    for (1,2) {
      chomp;
    ...
    
    @array = map  { $_++ } (1,2);
    @array = grep { $_++ } (1,2);
    
  3. or download this
    sub incr {
      $_[0]++;
    ...
    my $n = 1;
    incr($n); # good
    incr(1);  # bad
    
  4. or download this
    @array = sort { $a++ } (1,2);
    
  5. or download this
    my @bad;
    $bad[0] = [1];
    $bad[2] = [2];
    @bad = sort {$a->[0] <=> $b->[0]} @bad;
    
  6. or download this
    for (1,2) {
      my $data = prompt_user();
    ...
         # Do stuff
       }
    }
    
  7. or download this
    for (1,2) {
        while (<STDIN>) {
        }
    }
    
  8. or download this
    $_++ for (1,2);
    $_++ for (1,@array);
    @array = map {$_++} (1,@array);
    
  9. or download this
    my @array = (1,2);
    for (@array) {
      $_++;
    }
    
  10. or download this
    my ($x,$y) = (1,2);
    for ($x,$y) {
      $_++;
    }