Help for this page

Select Code to Download


  1. or download this
        %hash = ();
        foreach $_ (@array) {
          $hash{getkey($_)} = $_;
        }
    
  2. or download this
      my %res = map {
        $_ => do {
    ...
            $re;
        } if !$res{$_};
      } @words;
    
  3. or download this
      my %res;
      foreach my $word (@rw) {
    ...
          $re;
        }
      }
    
  4. or download this
    Benchmark: running foreach, map_it for at least 5 CPU seconds...
       foreach:  6 wallclock secs ( 5.34 usr +  0.00 sys =  5.34 CPU) @ 28
    +6.87/s (n=1531)
        map_it:  5 wallclock secs ( 5.15 usr +  0.01 sys =  5.16 CPU) @ 13
    +4.77/s (n=695)
    
  5. or download this
      my @b = (7,5,5,6);
      my @a;
      @a = map { $_ > 5 ? $_ : $a[0] } @b;