<?xml version="1.0" encoding="windows-1252"?>
<node id="590607" title="secret code generator" created="2006-12-19 00:42:09" updated="2006-12-18 19:42:09">
<type id="115">
perlquestion</type>
<author id="519234">
xiaoyafeng</author>
<data>
<field name="doctext">
Hi gurus,&lt;br&gt;&lt;br&gt;
I have big trouble!Last day, a python fan have claimed perl is a garbage language.python is much better than it. And raise a question to test perl's "ability":
&lt;br&gt;&lt;br&gt;
using letters of a string,enumerate all secret code.
&lt;br&gt;&lt;br&gt;
below is my code(I admit it's a garbage)
&lt;code&gt;
$letters = shift @ARGV ||"ABC";
@letter = split //,$letters;
for $a (1..$#letter) {
       for $b (1..$#letter) {
               for $c (1..$#letter) {
                          $scode = $letter[$c].$letter[$b].$letter[$a];
print $scode."\n";
}
}
}
&lt;/code&gt;
below is his code (with python)
&lt;code&gt;
import   string  
   
  DEFAULT_CHAR_SET     =   string.letters   +   string.digits   +   string.punctuation  
   
  class   PasswordGenerator(object)   :  
          def   __init__(self,   seeds   =   DEFAULT_CHAR_SET)   :  
                  self.seeds     =   seeds  
                  self.Outer     =   None  
                  self.cursor   =   0  
          def   next(self)   :  
                  self.cursor   +=   1  
                  if   self.cursor   ==   len(self.seeds)   :  
                          self.cursor   =   0  
                          if   not   self.Outer   :  
                                  self.Outer   =   PasswordGenerator(self.seeds)  
                          else   :  
                                  self.Outer.next()  
          def   value(self)   :  
                  if   self.Outer   :  
                          return   self.Outer.value()   +   self.seeds[self.cursor]  
                  else   :  
                          return   self.seeds[self.cursor]  
          def   __iter__(self)   :  
                  while   1   :  
                          yield   self.value()  
                          self.next()  
           
  if   __name__   ==   "__main__"   :  
          g   =   PasswordGenerator()  
          for   i   in   g   :  
                  print   i   
&lt;/code&gt;
&lt;br&gt;
&lt;br&gt;
I'm a perl fan and zealot,but not a accomplished programmer.So my question is:&lt;br&gt;
1.Who can transfer his code to perl, or tell me algorithm of his code? I don't know python at all!&lt;br&gt;
2.We could write a better code with perl,couldn't we?&lt;br&gt;&lt;br&gt;
Thanks in advance for answer my foolish and childish question!&lt;br&gt;
All responds are appreciated!
</field>
</data>
</node>
