Here are some suggestions on printing multilines such as ASCII art.


Try #1

Simply encapsultate all your print statements in a subroutine - since you are printing to a socket ($client) you should pass it as an arg to the sub - notice my use of whitespace to INDENT the code inside the BRACES:
sub print_sucky_bunny { my ($client) = shift @_; print $client "\n\r "; print $client "\n\r /| __ "; print $client "\n\r / | ,-~ / "; print $client "\n\r Y :| // / "; print $client "\n\r | jj /( .^ "; print $client "\n\r >-\"~\"-v\" "; print $client "\n\r / Y "; print $client "\n\r jo o | I a +m a sucky ASCII Art bunny"; print $client "\n\r ( ~T~ j And + i am filling in temporarily"; print $client "\n\r >._-' _./ So +if you dont like me"; print $client "\n\r / \"~\" | You + can suck my ****"; print $client "\n\r Y _, | "; print $client "\n\r /| ;-\"~ _ l "; print $client "\n\r / l/ ,-\"~ \\ "; print $client "\n\r \\//\\/ .- \\ "; print $client "\n\r R / Y "; print $client "\n\r O I ! "; print $client "\n\r W _\ /\"\ "; print $client "\n\r (\" ~----( ~ Y. ) "; }
But printing inside a sub like this is not very modular, imagine if you wanted to store the ASCII art in a variable for latter use - this would always print! So, lets use a scalar instead:


Try #3

WAIT FOR IT!!!


Try #2

sub create_sucky_bunny { my $bunny; $bunny .= "\n\r "; $bunny .= "\n\r /| __ "; $bunny .= "\n\r / | ,-~ / "; $bunny .= "\n\r Y :| // / "; $bunny .= "\n\r | jj /( .^ "; $bunny .= "\n\r >-\"~\"-v\" "; $bunny .= "\n\r / Y "; $bunny .= "\n\r jo o | "; $bunny .= "\n\r ( ~T~ j "; $bunny .= "\n\r >._-' _./ "; $bunny .= "\n\r / \"~\" | "; $bunny .= "\n\r Y _, | "; $bunny .= "\n\r /| ;-\"~ _ l "; $bunny .= "\n\r / l/ ,-\"~ \\ "; $bunny .= "\n\r \\//\\/ .- \\ "; $bunny .= "\n\r R / Y "; $bunny .= "\n\r O I ! "; $bunny .= "\n\r W _\ /\"\"; $bunny .= "\n\r (\" ~----( ~ Y. ) "; return $bunny; }
Now we are getting somewhere - we can now use this subroutine (notice that the name changed to reflect it's PURPOSE) 2 ways:
my $ascii_bunny = create_bunny(); # or print $client create_bunny();
Much better. But that looks like Java code - ick. Perl is smarter, and doesn't restrict us to having to break strings across multiple lines, we can do this:
my $foo = "bar baz qux "; # look ma, no \n's!!
Perl also provides the q() operator, which is just like single quotes:
my $foo = q(bar baz qux );
The cool thing about q() is you can use other chars as delimiters -  q{cool} q/cool/ q#cool# q{cool}. Since bunny does not contain any braces in it's ASCII art, we can safely use it for . . .

Try #3

Here i use the q() (AKA, q{}) operator to get the ASCII art into $bunny, then i use the s/// operator to add leading space (notice the x operator where $spaces is defined) as well as append \r to each line (\n is already there!). i also removed all backslashes that were being used to escape meta-characters - as a result, the bunny was harmed:
sub create_bunny { my $spaces = ' ' x 20; my $bunny = q{ /| __ / | ,-~ / Y :| // / | jj /( .^ >-"~"-v" / Y jo o | I'm an ASCII Art bunny ( ~T~ j And i'm fillin' in temporarilay >._-' _./ But at least i can that i / "~" | Was created in a more Perl-ish way! Y _, | (did i just say that out loud?) /| ;-"~ _ l / l/ ,-"~ \ / / / .- \ R / Y O I ! W _\ /"\ (" ~----( ~ Y. ) }; $bunny =~ s/(.*)/$spaces$1\r/g; return $bunny; } print $client create_bunny();
Be sure and read up on q() and it's cousins, qq(), qr(), and qx() at perlop.

jeffa


In reply to (jeffa) Re: Out of memory by jeffa
in thread Out of memory by thran

Title:
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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.