CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
hard to explain....

 



ultimategamer2k
User

May 25, 2001, 1:26 PM

Post #1 of 6 (838 views)
hard to explain.... Can't Post

how would i make it so that i could open a questions file that is set up like this
do you care?:whatever:o ya:no way!:hells no:okay
now, the first one "do you care?" is the main question, the rest are the answers. The number of answers can very, so there could be 4, like there is now, or there could be 5, 6, 100. I want to be able to make a loop, and put each question in a hash... and i have no clue about how to do this
please help
thanks!

-------------------------------------------------------------
visit my web site at <a href=http://ultimategamer.cjb.net>here</a>


mhx
Enthusiast / Moderator

May 25, 2001, 1:39 PM

Post #2 of 6 (836 views)
Re: hard to explain.... [In reply to] Can't Post

Ok, if each line of the file contains a colon separated list of one question and some answers, this could be the solution:

Code
my %questions = (); 

open FILE, 'filename';
while( <FILE> ) {
my($quest,@answer) = split ':';
$questions{$quest} = [@answer];
}
close FILE;

I haven't tested this, but it should at least give you an idea. It creates a hash that has the question a the key and an array reference as the value.

-- Marcus



ultimategamer2k
User

May 25, 2001, 3:10 PM

Post #3 of 6 (831 views)
Re: hard to explain.... [In reply to] Can't Post

o...ya....
lol
im lost

-------------------------------------------------------------
visit my web site at <a href=http://ultimategamer.cjb.net>here</a>


randor
User

May 25, 2001, 3:24 PM

Post #4 of 6 (830 views)
Re: hard to explain.... [In reply to] Can't Post

ultimategamer2k

im not sure what you need to do with this hash, so i am not sure how you want it added? as in each answer a keyword, and each value being the amount of those replies?

please explain a little better as to your intentions and i will see what i can do to help you out...



kojr
Novice

May 26, 2001, 5:32 AM

Post #5 of 6 (820 views)
Re: hard to explain.... [In reply to] Can't Post

I think ultimategamer2k like to ask
a question ( a unit question i.e $quest) can generate A answer ($answer which is selected RANDOMLY from@answer) whenever you browse it.

So, when you click the script it show up
do you care?
whatever


the another click would be
do you care?
o...ya..

third click would be
do you care?
lo!

If it had 100 answers it generate 100 different answers RANDOMLY
very intersting question.






kojr
Novice

May 28, 2001, 4:54 AM

Post #6 of 6 (801 views)
Re: hard to explain.... [In reply to] Can't Post

I have seen a script about fortune telling. It generate html page which you can modify the content of the page catering to your need.
Here is demonstration...

http://csss.hypermart.net/lucky/lucky.cgi

The script...

#!/usr/local/bin/perl


$kind = 1;


$luck1 = 'http://csss.hypermart.net/lucky/good.htm';
$luck2 = 'http://csss.hypermart.net/lucky/good1.htm';
$luck3 = 'http://csss.hypermart.net/lucky/ok.htm';
$luck4 = 'http://csss.hypermart.net/lucky/nogood.htm';
$luck5 = 'http://csss.hypermart.net/lucky/nogood1.htm';

&rand;
if ($kind == 0) {
&omikuji;
}

elsif ($kind == 1) {
print "Location: $luck\n\n";
}

else {
print "$luck\n";
}
exit;
sub rand {
srand;
$x = rand;

$x = int($x * 100);

if ($x < 20) { $luck = "$luck1"; }

elsif ($x < 40) { $luck = "$luck2"; }

elsif ($x < 70) { $luck = "$luck3"; }

elsif ($x < 90) { $luck = "$luck4"; }

else { $luck = "$luck5"; }
}
sub omikuji {
print "Content-type: text/html\n\n";
print <<"HTML";
<html>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=big5">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<head><title>Do yoy care</title></head>
<body bgcolor="#F5F5F5" text="#000000">
<center><h3>?なたの今日の運勢</h3>
<P><font color="#FF0000" size=4><B>$luck</B></font>
<hr size=1>
<form><input type="button" value="Submit" onClick="history.back()">
</form>
</body></html>
HTML
}



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives