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> </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
"id|vote|number of votes" 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 "The Complete Reference Perl" 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>
>Hi! <br>
> <br>
> I'd love to help, but I couldn't find a single question mark in your
<br>
>post...could you be a little more specific about what you want to do?
<br>
> <br>
> I believe that you want to put all this info into a file, but I'm
not <br>
>sure what that has to do with hashes. (I'm guessing I'm just being
dense, <br>
>as usual...but I have to say that your use of the word
"nominate" has <br>
>thrown me!) <br>
> <br>
>So, could you rephrase the question? <br>
> <br>
>Brian A. Sayrs <br>
>Owner, Southwind Solutions <br>
><a href="http://boards.sowinso.com/" eudora="autourl"><font color="#0000FF"><u>http://boards.sowinso.com</a></font></u>
<br>
> <br>
>-----Original Message----- <br>
>From: Stuart McDonald [SMTP:stuart(at)fourelephants.com] <br>
>Sent: Thursday, February 10, 2000 8:35 PM <br>
>To: hwg-techniques(at)hwg.org <br>
>Subject: Perl hash query <br>
> <br>
>Hi, <br>
> <br>
>I'm currently trying to write a script which will take three values
off a <br>
>form (ID, number and score) and write them to a file which I can then
<br>
>retrieve later and perform calculations on both number and score.
Initially <br>
>I had the script creating three seperate files which works fine, but
this <br>
>will eventually result in my creating hundreds and hundreds of hils
in my <br>
>directory, which I'm not real thrilled about. <br>
> <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 (& don't I just feel like one!) does not
explain <br>
how to nominate a key value for a hash. <br>
<br>
Any help would be much appreciated. <br>
<br>
Stuart<br>
</html>
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA