Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Bad ascii art

by perldeveloper (Scribe)
on Aug 25, 2004 at 21:00 UTC ( #385817=note: print w/replies, xml ) Need Help??

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:


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

      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($=)}

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385817]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2023-03-27 10:18 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (64 votes). Check out past polls.