R
R
ruboss2015-09-19 00:29:48
Perl
ruboss, 2015-09-19 00:29:48

How to interpret PERL code in PHP?

Hi all! Have I translated perl to php correctly?
PERL

my @indexes;
        for my $i ( 0 .. $L - 1 ) {
            my %seen;
            while (1) {
                my $rand = int( rand( $self->d * $SCALE ) );
                if ( !$seen{$rand} ) {
                    $seen{$rand} = 1;
                    last if keys %seen == $self->k * $SCALE; // ??????
                }
            }
            push( @indexes, [ sort { $a <=> $b } keys %seen ] );
        }
        $self->_indexes( \@indexes );

PHP
$indexes = null;
    for($q=0; $q<$L; $q++){
      $seen = null;
      while(true){
        $rand = rand(0, $d*$SCALE);
        if(!$seen[$rand]){
          $seen[$rand] = 1;
          if(count($seen) == $k * $SCALE)
            break;
        }
      }
      $indexes[] = asort($seen);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadz Goldman, 2015-09-19
@nadz

Yes, you translated correctly.
Exactly the opposite.
You need to simply open any reference book on perl and read about hashes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question