Anyone know how to...

They have: 117 posts

Joined: Mar 2000

Put a variable within a variable?? I need to know how to do something like this:

$FORM{votes$num}

Where $num is a number so it can tell the difference between a number of forms. (Called "votes" then a number to identify it.) When I use the code above I get this error:
Can't call method "votes" without a package or object reference at /home/users/j/jsnow/public_html/cgi-bin/polls/edit.cgi line 20.

If you need to see the script in action to help, I'm willing to let you see it. Thanks!

--Edge

They have: 568 posts

Joined: Nov 1999

The $FORM{'name'} is the default variable used by form processors. Why would you want your $FORM{''} to over write it?

And the reason for the error is you can not have $num in the $FORM{''} hash. It won't call up that variable for some reason.

If you wanted to add the $num variable onto the $FORM{} you should use $FORM{'num'} .= $votes.

Hope that helped.

[This message has been edited by Orpheus (edited 18 March 2000).]

They have: 117 posts

Joined: Mar 2000

Yes, I'd do that, but I already have some different forms named by numbers. So I can't have 2 forms with the same name, can I??

Do you need to see the script in action for a better explanation? I have it online if that's the case.

--Edge

They have: 568 posts

Joined: Nov 1999

yeah, please send the URL

They have: 117 posts

Joined: Mar 2000

Okay, go to http://www.xmission.com/~jsnow/cgi-bin/polls/vote.cgi

Click on "View Results" then login. The password is "oreos". This is where I need help. The forms for the choice names are numbered, so I just need a way to do the number of votes as well and the script will be finished!!

Would you like to see the source code as well??

--Edge

They have: 568 posts

Joined: Nov 1999

the source would be the best.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

What about doing it the long way...?

Make a list: @whatever = ();

And make the elements of the list: $whatever[$num] = $FORM{'whatever'};

??

There is obviously more involved and I don't want to do it for you as I am new to Perl, but maybe that's an idea?

Suzanne

------------------
Zero Cattle
Suzanne
Tables DeMystified

They have: 568 posts

Joined: Nov 1999

Ok, after a little research (i was doing a script of my own and i had to do this). I found something you may be able to use. If you use " instead of ' in the $form{''} you can include variables.

I dont know why i missed it before. So you would use $FORM{"votes$num"} and if this was in a print "" line you would put a \ before the ". So the final result would be

print "$FORM{\"votes$num\"}";

Hope that helped.

They have: 117 posts

Joined: Mar 2000

It worked!!!!! Thank you soooooooooooooo much!!!!!!!!!!

--Edge

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.