http://qs321.pair.com?node_id=385817


in reply to Bad ascii art

I'd say the idea is not too complicated -- for every + you increase the ascii code, for every - you decrease it. In between, at every non-space character, you print the character corresponding to it. Or something like that, fact is it took me about 2 minutes to figure this out, and I think it's because the main body of the program is obvious (the for through each character loop).

How about the following suggestions to `improving the non-readability of your code':
  1. Use special Perl variables ($/ $= $,)
  2. Avoid overusing obvious keywords (eval, split), go for regexps if possible
  3. When using regexps, feel free to use characters other than forward slashes
  4. When quoting strings, feel free to use other quoting techniques (qq[])
I made a few superficial changes based on what I said, but I don't have Perl here, so I'll hope you at least get the idea if it doesn't run. Oh and I don't mean to offend if you already knew these things.
$==109;for(split//,q{ / ++++++ ++o-------=++ ++ ++_--------------<+ ++,+++++++++ +/ -------- -- -/ { ){m?\s??():s:-|+:$=$&$&:?eval:print chr($=)}

Replies are listed 'Best First'.
Re^2: Bad ascii art
by muntfish (Chaplain) on Aug 26, 2004 at 08:30 UTC

    Thanks for the suggestions - and for not slagging off my code too much!

    I like your changes, although I can't get them to work. I notice you have q{{ which I fixed to q{}, also you need to escape the + in the substitution regex. But now all I get is a long line of mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm !

    I'll keep looking, hopefully I will learn something by fixing it! Thanks again.

    Update: Also need to escape the $= in the right hand side of the substitution... which gives the result:

    mmmmmmmmmmmmmmmmmsssunppprtfgggirrrrssssssskkkkkiiiiiiiiihhhhhhhhhhhh

    which has all the right letters (in the right order) but a "few" extra ones!

    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&;
      Well, I hope I'll make it up to you with this adaptation, which I did test on Perl. It's a bit more obscure than what I originally suggested -- yet still same principles.
      $=+=49;$;= q; .;; m; | ;?49:s|\+\|-|\$=$&$&|? eval:$;=~s;.$;$=$&$&;for split//,q; / ++++++ ++o-------=++ ++ ++_--------------<+ ++,+++++++++ +/ -------- -- -/;; $_=$;;s;..$;;;print eval;
      I left the ascii art to you.

      OK, it's the m?? that is upsetting it. White space is not being filtered. The following works - but I'm going to start again to find a more obscure way of generating the characters...

      $==109;for(split//,q{ / ++++++ ++o-------=++ ++ ++_--------------<+ ++,+++++++++ +/ -------- -- -/ }){m^\s^?():s:-|\+:\$=$&$&:?eval:print chr($=)}
      s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&;