Re : Perl hash query

by Stuart McDonald <stuart(at)fourelephants.com>

 Date:  Sat, 12 Feb 2000 10:50:56 +0700
 To:  hwg-techniques(at)hwg.org
  todo: View Thread, Original
<html>
<table border=0>
<tr><td width=780>&nbsp;</td></tr>
</table>
Brian,<br>
<br>
Looking back at my question it was a bit vague, so here is some more
details: (please excuse incorrect language I'm still learning)<br>
<br>
I am writing a routine within a script that is a type of ranking system.
The users will have the opportunity throughout the site to rank items
with a score of one to five and then depending on the score a number of
stars is shown (you guessed it - one to five stars!). Now the script
works by taking from the user two values (submitted by a form) which are
the ID if the item eg 725 (in a hidden field) and their vote eg 4. The
script then uses the ID number to open two seperate files which will are
725score.txt and 725num.txt (these two files are created automatically
the first time someone votes) and adds the score of 4 to the value of
725score.txt and increments 725num.txt then divides the new score by the
incremented value of 725num.txt. This result is then moved into the
graphic routine which displays the number of stars.<br>
<br>
Now this all works fine (and I'm actually pretty chuffed with it as it's
the first script I ever wrote!!) but as the site will allow people to
ranking hundreds and hundreds of items to rank I'm not thrilled about
having hundreds and hundreds of files each with a single number in
them.<br>
<br>
What I would like to do is simply use one file data.txt which would hold
all the above with the ID number being the key, but I just cannot figure
out how to do it. I think what I want is for the script to open data.txt,
search for the ID number abd if it is there pull out the details, say
&quot;id|vote|number of votes&quot; perform the calculation and return
the new values to the file where id is a unique value. I'm not sure if
hashes are what I am after or not - I'm really confused now. So, that's
my question, how do I do this!<br>
<br>
If I am missing something really obvoius or am treating the data from the
wrong angles, please let me know. I've been using the Dummies Book and
Osbornes &quot;The Complete Reference Perl&quot; but are now cursing not
getting the O'Reilly book which is prohibitivly expensive here in
Bangkok.<br>
<br>
Many Thanks<br>
<br>
Stuart<br>
<br>
At 07:21 AM 11 02 2000 -0800, you wrote: <br>
&gt;Hi! <br>
&gt; <br>
&gt; I'd love to help, but I couldn't find a single question mark in your
<br>
&gt;post...could you be a little more specific about what you want to do?
<br>
&gt; <br>
&gt; I believe that you want to put all this info into a file, but I'm
not <br>
&gt;sure what that has to do with hashes. (I'm guessing I'm just being
dense, <br>
&gt;as usual...but I have to say that your use of the word
&quot;nominate&quot; has <br>
&gt;thrown me!) <br>
&gt; <br>
&gt;So, could you rephrase the question? <br>
&gt; <br>
&gt;Brian A. Sayrs <br>
&gt;Owner, Southwind Solutions <br>
&gt;<a href="http://boards.sowinso.com/" eudora="autourl"><font color="#0000FF"><u>http://boards.sowinso.com</a></font></u>
<br>
&gt; <br>
&gt;-----Original Message----- <br>
&gt;From: Stuart McDonald [SMTP:stuart(at)fourelephants.com] <br>
&gt;Sent: Thursday, February 10, 2000 8:35 PM <br>
&gt;To: hwg-techniques(at)hwg.org <br>
&gt;Subject: Perl hash query <br>
&gt; <br>
&gt;Hi, <br>
&gt; <br>
&gt;I'm currently trying to write a script which will take three values
off a <br>
&gt;form (ID, number and score) and write them to a file which I can then
<br>
&gt;retrieve later and perform calculations on both number and score.
Initially <br>
&gt;I had the script creating three seperate files which works fine, but
this <br>
&gt;will eventually result in my creating hundreds and hundreds of hils
in my <br>
&gt;directory, which I'm not real thrilled about. <br>
&gt; <br>
I'm playing around with hashes but just can't get it to work as the book
<br>
I've got (perl for Dummies (&amp; don't I just feel like one!) does not
explain <br>
how to nominate a key value for a hash. <br>
&nbsp;<br>
Any help would be much appreciated. <br>
&nbsp;<br>
Stuart<br>
</html>

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA