Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi gurus,

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":

using letters of a string,enumerate all secret code.

below is my code(I admit it's a garbage)
$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"; } } }
below is his code (with python)
import string DEFAULT_CHAR_SET = string.letters + string.digits + st +ring.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(s +elf.seeds) else : 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() if __name__ == "__main__" : g = PasswordGenerator() for i in g : print i

I'm a perl fan and zealot,but not a accomplished programmer.So my question is:
1.Who can transfer his code to perl, or tell me algorithm of his code? I don't know python at all!
2.We could write a better code with perl,couldn't we?

Thanks in advance for answer my foolish and childish question!
All responds are appreciated!

In reply to secret code generator by xiaoyafeng

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (15)
    As of 2015-10-13 14:35 GMT
    Find Nodes?
      Voting Booth?

      Does Humor Belong in Programming?

      Results (309 votes), past polls