[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

oops, continuing ``Re: [FWP] RFC''



>$sindex = chr(64 + (localtime)[3]);
>$eindex = ((ord($sindex) + 9) < 91) ?
>              chr(ord($sindex) + 9) :
>              chr(((ord($sindex) + 9) - 90) + 64);

If $sindex is "Y", then $eindex is "H", but ("Y" .. "H") is only
("Y" .. "Z").  So you mean to do something like:

  $start = chr(64 + (localtime)[3]);
  $end = chr(
    ord($start) + 9 +
    ($start gt 'Q' and 64 - 90)
  );

>for (($ARGV[0]..$ARGV[1]) || 0) {

(EXPR .. EXPR) in scalar context is the flip-flop operator.  And I highly
doubt $_ =~ /$ARGV[0]/.  So that is ALWAYS for (0) { ... }.  And wouldn't
it be more normal to do:

  for (1 .. ($ARGV[0] || 1)) {
    ...
  }

That way, only one argument is expected, and it defaults to 1.

>  my @num = ($sindex..$eindex);

We'll have to change this.  (And the name should be @num...)

  my @chars = $start lt $end ?
    ($start .. $end) :
    ($start .. 'Z', 'A' .. $end);

>  for (my $i = $#num; $i > 0; $i--) {
>    my $swapper = int rand(1+$i);
>    if ($swapper < $i) {
>      @num[$i,$swapper] = @num[$swapper,$i];
>    }
>  }
>  print "@num\n";
>}

Changes of ``num'' to ``chars'' as needed.

Hmm, this isn't REALLY a Fisher Yates shuffle, is it...

  $i = 0;
  while ($j = rand(@array - $i), $i++ < @array) {
    @array[$i-1,$j] = @array[$j,$i-1];
  }

That's FY.  I'm not so sure about yours.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe