> From: The Black Man <[EMAIL PROTECTED]>
> Date: Tue, 2 Oct 2001 15:14:50 -0700 (PDT)
> To: [EMAIL PROTECTED]
> Subject: variable variable-names
> 
> Hi all,
> 
> I'm trying to write a script that will pull out values
> for form data radio buttons for muliple answers. This
> is what a standard line looks like:
> 
> <INPUT TYPE="radio" NAME="answer1" VALUE="blah">Blah
> 
> For each question I've tried to make up a separate set
> of arrays containing the button values:
> 
> open (QUES, "<questions.poll");
> foreach $line (<QUES>) {
> chomp $line;
> if ($line =~
> m|[^"]*NAME="answer(\d)"\s*VALUE="([^"]*)"|) {
> $num = $1;
> $value_label = $2;
> push @question_$num, $value_label;
> }
> }

If you must use a variable to name another variable, use something like
this:

push @{"question_$num"}, $value_label;

The braces allow you to treat the var name like any old string. The quotes
make "question_$num" an interpolated string (just like print
"question_$num";, etc).

I, however, would use a multilayered array of sorts. (look in the Camel Book
under "Data Structures" for more info on that.)

Hope that helps.

> 
> but I keep getting the following error message:
> 
> Scalar found where operator expected at
> ./grab_qustions.pl line 45, at end of line
> (missing operator before ?)
> syntax error at ./grab_questions.pl line 45, near
> "@question_$num"
> 
> 
> I've also tried using @question_${num}, but that
> soesn't work either.  From the error message, I'm
> assuming that I am making multiple errors, but I'm
> stumped.  Can anyone help?
> 
> 
> Thanks,
> 
> Drunken Master
> 
> 
> 
> =====
> "Still pond, frog jumps in. Splash!"
> 
> "There he goes...one of God's own prototypes.
> A high-powered mutant of some sort, never meant for mass production...
> Too weird to live, and too rare to die..."
> 
> AIM: TaoJonesin


-Michael Kelly
Email: [EMAIL PROTECTED]
The Web: http://jedimike.hypermart.net 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to