Help for this page

Select Code to Download


  1. or download this
      PCHR = ["K", "Q", "R", "B", "N", "P"]
      w1 = "QRKPNB"
      w2 = "".join(sorted(w1, key=PCHR.index)) # Translate this to Perl ..
    +.
      print(w1 + " -> " + w2)
    
  2. or download this
      my $i = 0;
      use constant PCHR => split //, 'KQRBNP';
    ...
      my $w1 = 'QRKPNB';
      my $w2 = join '', sort { $pchr{$a} <=> $pchr{$b} } split //, $w1;
      print "$w1 -> $w2\n";