phoenix9 has asked for the wisdom of the Perl Monks concerning the following question:
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:
It would show up as:print "enter username:"; chomp($uname=<STDIN>); $USERFILE='configs/'.$uname.'.usr'; open(USERFILE); # Whatever the solution to my problem is print $a + $b;
the only thing I can figure out to do is make the .usr file:enter usename:test1 3
with the perl:1 2
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.chomp($a = <USERFILE>); chomp($b = <USERFILE>);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Working with a legable config file
by bbfu (Curate) on Apr 03, 2004 at 02:21 UTC | |
|
Re: Working with a legable config file
by Zaxo (Archbishop) on Apr 03, 2004 at 02:26 UTC | |
|
Re: Working with a legable config file
by bart (Canon) on Apr 03, 2004 at 02:46 UTC | |
|
Re: Working with a legable config file
by Vautrin (Hermit) on Apr 03, 2004 at 04:13 UTC |