Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Using a for() statement to create a variable??

Reply
Thread Tools

Using a for() statement to create a variable??

 
 
dayton@gecko.org
Guest
Posts: n/a
 
      03-26-2005
I have a form that is dynamiclly generated from a database. Using the
CGI module, I'm trying to parse the parameters returned, but since the
number of paramaters changes I can't get the variables assigned...

What I'm trying:
--------------
$count='1';
while (my(@data)=$table_data4->fetchrow_array) {
print qq|
<tr><td><input name=rs$count type=text
maxlength=7 size=7 value=$data[0]><td>$data[1]
|;
$count++;
}
--------------------

which correctly populates the table but then when I try to parse the
parms..

(like : if (param()){ $buh = param('buh') || '';}

I run into my problem. I've tried:

----------------------
for ($i=1;$i<=$number;$i++)
$R$i="rs$i";
}
----------------------

and the error I get is:

Scalar found where operator expected at ./test line 5, near "$RS$i"
(Missing operator before $i?)
syntax error at ./test line 5, near "$RS$i"
Execution of ./test aborted due to compilation errors.


How can I auto-generate the variables based on the # of params created
by the form?

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      03-26-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have a form that is dynamiclly generated from a database. Using the
> CGI module, I'm trying to parse the parameters returned, but since the
> number of paramaters changes I can't get the variables assigned...

[...]
> for ($i=1;$i<=$number;$i++)
> $R$i="rs$i";

[...]
> How can I auto-generate the variables based on the # of params created
> by the form?


You don't. Symbolic references are evil, please see the FAQ and google. This
has been discussed to death many, many times over.
Instead us a more suitable data structure like a hash. Again, the FAQ
explains how ("How can I use a variable as a variable name?").

jue


 
Reply With Quote
 
 
 
 
robic0@yahoo.com
Guest
Posts: n/a
 
      03-26-2005
Dynamically generate the code block, then use "eval" on it?

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-26-2005
"(E-Mail Removed)" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> Dynamically generate the code block, then use "eval" on it?


To do what?

Sinan
 
Reply With Quote
 
robic0@yahoo.com
Guest
Posts: n/a
 
      03-26-2005
"To do what?"

Weren't you the guy insulting me on another post....

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      03-26-2005

[Full-quote]
(E-Mail Removed) wrote:
> "To do what?"
>
> Weren't you the guy insulting me on another post....


Who is "you"? Whom are you talking to?
Usenet is a 1-to-many communications form. Do you mean every single reader
of this newsgroup?

jue


 
Reply With Quote
 
robic0@yahoo.com
Guest
Posts: n/a
 
      03-26-2005
""Who is "you"? Whom are you talking to?""

JH #2 - Please speak english in clear, readable and understandable
expressions.
What are "you" talking about?

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      03-26-2005
(E-Mail Removed) wrote:
> ""Who is "you"? Whom are you talking to?""


I suppose this is a quote from an article I posted. It is common courtesy to
mark quoted text as such and to provide an attribution.

> JH #2 - Please speak english in clear, readable and understandable
> expressions.
> What are "you" talking about?


I strongly suggest that you read up on basic Nettiquette ASAP. You are on
the brink of being granted membership in many killfiles.

jue


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      03-26-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:

> JH #2 - Please speak english in clear, readable and understandable
> expressions.



We will do that when you do that.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
robic0@yahoo.com
Guest
Posts: n/a
 
      03-27-2005
"I suppose this is a quote from an article I posted. It is common
courtesy to
mark quoted text as such and to provide an attribution.


> JH #2 - Please speak english in clear, readable and understandable
> expressions.
> What are "you" talking about?



I strongly suggest that you read up on basic Nettiquette ASAP. You are
on
the brink of being granted membership in many killfiles.
"

I suggest you not mention "kill" as an attribute within your reply.
Should you feel the need
to kill someone, I suggest you consult proffessional help immediatly.
In America, we do not
take kindly to threats from individuals from foreign countries. Your
time may well be better
spent mastering english and gaining insite on American culture.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
Using CSS to Create a Bank Statement nightstar@gmail.com HTML 6 08-11-2005 02:14 AM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM



Advertisments