472,146 Members | 1,219 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

Counters in variable names.

My HTML reads a file and writes out field names to include a counter so I have fields like

<input type=text name=surname$counter><input type=checkbox name=update$counter>

When they click update these fields are sent to the update program for update.

If the person changes this field they will also tick the change checkbox and I want to be able to loop through all the fields and update them as below

UPDATE Program
for($counter=0 ; $counter < $totalrecords ; $counter++)
{
if ($update$counter)
{ blah blah}

The problem is that Perl does not seem to like me adding a variable ($counter) to a variable name ($update) and the only other way would be long winded like
if ($update1) {Blah Blah}
if ($update2) {Blah Blah}

How can I get a variable to be part of anothers variable name.

G
Jul 19 '05 #1
2 3376
dw

"Gary" <re*****@netlink.info> wrote in message
news:W8r7c.12945$1e1.1473@lakeread06...
My HTML reads a file and writes out field names to include a counter so I have fields like
<input type=text name=surname$counter><input type=checkbox name=update$counter>
When they click update these fields are sent to the update program for update.
If the person changes this field they will also tick the change checkbox and I want to be able to loop through all the fields and update them as
below
UPDATE Program
for($counter=0 ; $counter < $totalrecords ; $counter++)
{
if ($update$counter)
{ blah blah}

The problem is that Perl does not seem to like me adding a variable ($counter) to a variable name ($update) and the only other way would be long
winded likeif ($update1) {Blah Blah}
if ($update2) {Blah Blah}

How can I get a variable to be part of anothers variable name.

G


how about using something like:
${"update$counter"}

however, I assume that you are using CGI.pm and can use something like:
$q->param("update$counter")
or stuff the values into a hash:
$update{$counter} = $q->param("update$counter")
Jul 19 '05 #2
"dw" <me@verizon.invalid> wrote in message news:<GB*******************@nwrddc01.gnilink.net>. ..
"Gary" <re*****@netlink.info> wrote in message
news:W8r7c.12945$1e1.1473@lakeread06...
How can I get a variable to be part of anothers variable name.

how about using something like:
${"update$counter"}


I am less rabid than some about these things but I really don't think
that showing the OP how to write a symref is a kind thing to do. You
can tell him that symbolic references are what he's talking about but
make him go RTFM to find out about symrefs and why he doesn't really
want them.

Since the OP is asking FAQ "How can I use a variable as a variable
name?" then the best and _most_ _helpful_ response is RTFFAQ. It is,
really. Some people will disagree with me on this, but that's
because they are wrong.

This newsgroup does not exist (see FAQ). Please do not follow-up here
without mentioning this.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jim Heavey | last post: by
4 posts views Thread by Chad Myers | last post: by
reply views Thread by Christopher Attard | last post: by
4 posts views Thread by Dmitry Duginov | last post: by
7 posts views Thread by James | last post: by
2 posts views Thread by Spam Catcher | last post: by
1 post views Thread by Ben | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.