Thread Unmatched [ in regex (14 answers)
Opened by Gast at 2007-09-07 01:09

Gast Gast
 2007-09-07 02:48
#99173 #99173
hi zuerst mal danke dass du um diese Uhrzeit noch hilfst.
Also es ist so hab ne Funktion GetQuestion
da wird die Datei geöffnet per zufall eine Zeile ausgelesen und dann zerschnitten und anschließend retour gegeben.

ich füg am besten den code hier dann siehst es selber.



Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
sub GetQuestion {
        $PointValue = $ScoreValues[rand($#ScoreValues)];
        if (rand(15) == 0) { $PointValue *= 2; }
        $FileNum = int(rand($TotalFiles))+1;
        $QNum = int(rand($QuestionDBinfo{$FileNum}[1]))+1;
        open(QFILE, $QuestionDBinfo{$FileNum}[0]) or die "Error opening the trivia file\n";
        for($i = 0; $i < $QNum; $i += 1) {
                $QuestionLine = <QFILE>;
        }
        close(QFILE);

        $d = substr($QuestionLine,0,1);
        $Question = (split(/[$d][$d]/,$QuestionLine))[1];
        $Category = (split(/[$d]/,$QuestionLine))[1];
        $Answer = (split(/[$d]/,$QuestionLine))[2];
        $QID = "F".$FileNum.".Q".$QNum;
        chomp($Question);
        if ($Category eq "Scramble") {
                @letters = ();
                for($i=0;$i<length($Question);$i+=1) {
                        push(@letters,substr($Question,$i,1));
                }
                @letters = shuffle(@letters);
                $Question = "";
for($i=0;$i<scalar(@letters);$i+=1) {
                        $Question = $Question." ".$letters[$i];
                }
                $Question = "Unscramble this word: ".$Question;
                $l = length($Answer) - 5;
                while ($l >= 0) {
                        if (int(rand(2)) == 1) { $PointValue *= 2; }
                        $l -= 3;
                }
        }

        @retval = ($PointValue, $QID, $Category, $Question, $Answer);

        return @retval;
}


die Funktion wird wiederum in einem andren Funktion aufgerufen.
Code (perl): (dl )
@Q = &GetQuestion;


wie löse ich das am besten???

View full thread Unmatched [ in regex