Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The provided perl is a little dated:

  $x = &z(1, 100, 3);
  
  sub z{
    $a = $_[0];
    $b = $_[1];
    $c = $_[2];
    $d = 0.0;
    $e = 0.0;
  
    for ($i = $a; $i <= $b; $i++){
      if($i % $c == 0) {
        $d = $d + 1;
      }
      else {
        $e = $e + 1;
      }
    }

    if($d > $e) {
      $d;
    }
    else {
      $e;
    }
  }
Fixed?

  $x = z(1, 100, 3);
  
  sub z{
    my( $a, $b, $c ) = @_;
    my $d = 0;
    my $e = 0;
  
    for ($a..$b){
      if($_ % $c == 0) {
        $d++;
      }
      else {
        $e++;
      }
    }
  
    if($d > $e) {
      return $d;
    }
    else {
      return $e;
    }
  }


This also clearly reminds me of one of the uses of perl. It's nice to use for prototyping something that can be implemented in ANSI C when necessary.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: