G'day spoonman2525,

Welcome to the monastery.

Here's another suggestion. You have multiple strings (for printing) that are hundreds of characters in length, wrap many times, and have huge amount of formatting (newlines and tabs) embedded in each string. Without actually running the code, it would be (virtually) impossible to visualise the output format. In addition, I suspect this might become something of a maintenance nightmare: consider a situation where you need to insert a phrase and then need to reposition a dozen or more newline ("\n") characters from the point of insertion to the end of the string.

I think you'll find the use of heredocs would be much easier. You can use these directly in the code or define them separately elsewhere in the code (such that the code logic is not obscured by large amounts of text).

Here's an example using part of the code in sub endingA {...}:

#!/usr/bin/env perl use strict; use warnings; print '-' x 40, "\n"; # (part of) Current code in sub endingA {...} print "\n\nYou prepare the escape pods for launch. One for yourself\n +and one for Doctor Willis. You quickly run back to the utility room\n +and carry him into the command room. You lay him down\nin one of the +escape pods, ...\n"; print '-' x 40, "\n"; print '-' x 40, "\n"; # Easier to read code for sub endingA {...} print <<'EOT'; You prepare the escape pods for launch. One for yourselfand one for Do +ctor Willis. You quickly run back to the utility roomand carry him in +to the command room. You lay him down in one of the escape pods, ... EOT print '-' x 40, "\n"; # Predefined text for use in sub endingA {...} my $endingA_text = <<'EOT'; You prepare the escape pods for launch. One for yourself and one for Doctor Willis. You quickly run back to the utility room and carry him into the command room. You lay him down in one of the escape pods, ... EOT print '-' x 40, "\n"; print $endingA_text; print '-' x 40, "\n";

Output:

---------------------------------------- You prepare the escape pods for launch. One for yourself and one for Doctor Willis. You quickly run back to the utility room and carry him into the command room. You lay him down in one of the escape pods, ... ---------------------------------------- ---------------------------------------- You prepare the escape pods for launch. One for yourself and one for Doctor Willis. You quickly run back to the utility room and carry him into the command room. You lay him down in one of the escape pods, ... ---------------------------------------- ---------------------------------------- You prepare the escape pods for launch. One for yourself and one for Doctor Willis. You quickly run back to the utility room and carry him into the command room. You lay him down in one of the escape pods, ... ----------------------------------------

Another, possibly better, alternative would be to define all these large tracts of text in an external file.

-- Ken


In reply to Re: Text Based Perl Game by kcott
in thread Text Based Perl Game by spoonman2525

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.