Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading in variable values from a file

Status
Not open for further replies.

Ito2233

MIS
Sep 2, 2003
77
US
Total PERL newbie here.
Let's say I have a text file with the following:

count = 485
lookfeel = 3245
navigation = 6709
usability = 9976
detail = 8567

These are answers from a questionnaire. They are running totals. Every time a questionnaire is answered, I'd like to add to the count and to the running totals. I would write a CGI script to read these values into variables, add to them, and then write the values back to this text file. What's the simplest way to do it?? I have found the tutorials on the web lacking in terms of file manipulation.
Thanks
 
you could do something like this;

my %hash; my $key; my $value;

open(F, $file);

while(<F>) {

($key, $value) = split(/\s=\s/);

$hash{$key} = $value;

}

then you can do things like;

$hash{'count'}++;
$hash{'usability'}--;

print "count = " . $hash{'count'};
 
What about if you want to make the value you read in become the variable name? Ie, I've got a conf file that has several lines, one is HOST = server

How do I take HOST and make it the variable name? Then make "server" it's value?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top