Help for this page

Select Code to Download


  1. or download this
      for @$r -> $x, $y {
        push @$pairs, [$x, $y];
      }
    
  2. or download this
    my $r2;
    my $flipper = 0;
    ...
        push @$r2, [ $_ ];
      }
    }
    
  3. or download this
    my %h=(@$r);
    for (keys %h) {
    ...
    }
    # or possibly
    # push @$r2, [$_, $h2{$_} ] for keys %h
    
  4. or download this
    my $i = 0;
    my $r2 = map {[ $r->[$i*2], $r->[$i++*2+1] ]}
             (0 .. $#{$r}/2 - 1);
        # or (0 .. scalar(@$r)/2 - 1)
    
  5. or download this
    for( my $i=0; $i < scalar @$r; $i += 2 ) {
      $r2->[$i/2] = [ @$r[$i, $i+1] ]
    }
    
  6. or download this
    my @copy = @$r;
    for( @copy ) {
        push @$r2, [ $_, shift @copy ];
    }
    
  7. or download this
    my @copy = @$r;
    while( @copy ) {
        push @$r2, [ shift @c, shift @c ];
    }
    
  8. or download this
      $r2 = [ map { [$r->[2*$_], $r[2*$_+1]] } 0 .. scalar @$r / 2 - 1 ]
    
  9. or download this
      $r2 = [ map { [@$r[2*$_, 2*$_+1]] } 0 .. scalar @$r / 2 - 1 ]
    
  10. or download this
    @copy = @$r;
    while (my @pair = splice @copy, 0, 2) {
      push @$r2, [@pair];
    }
    
  11. or download this
    #! /usr/bin/perl -w
    
    ...
      },
    );
    __END__