I have a friend who is writing a text based game, but as yet it had no save capabilities. I told him I'd right a save and load sub-routine for him because while im still new to it i know how to use filehandelers alot better than him.

Due to the simplicity of the game all that I need it to due is store variables in a text file from one running of the game until the next. The problem is I wanted the text file to be understandable instead of just a list of numbers so say the file (named test1.usr in a subfolder of the current directory named configs) is like this:

$a = 1 $b = 2

I am trying to figure out a way so that were I to run code like this:

print "enter username:"; chomp($uname=<STDIN>); $USERFILE='configs/'.$uname.'.usr'; open(USERFILE); # Whatever the solution to my problem is print $a + $b;
It would show up as:
enter usename:test1 3
the only thing I can figure out to do is make the .usr file:
1 2
with the perl:
chomp($a = <USERFILE>); chomp($b = <USERFILE>);
the only thing I can do with the current config (.usr) file is print it to STDOUT or another file. How can I keep the current formatting (and therfore legability) but still have the disired outcome.

~Phoenix9

P.S. this is a test version of the code. In the final it will be keeping track of actual information and will not just print 3. However, I bilieve the solution to this problem will work in the final version.

In reply to Working with a legable config file by phoenix9

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.