CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Variables

 



benn600
User


Apr 26, 2005, 1:50 PM

Post #1 of 4 (830 views)
Variables Can't Post

How can I open a variable with a variable inside the name of a variable? For example, $v1 = "2" and I want to open that variable. I know that $test = "1", so I do $v$test --and want test to be replaced with 1 in the variable. Thanks.
----------------------------------------------------------------------------
Wink http://www.ppcpathways.com/ Wink
Visit my new site devoted to reviewing the latest pocketpc products and news that I built in cgi-perl!


maximus
Novice

Apr 28, 2005, 6:50 AM

Post #2 of 4 (817 views)
Re: [benn600] Variables [In reply to] Can't Post

If I understand this correctly, u want to get $v1.

$v = "2";
$test ="1";
$x = "\$v$test";

print "$x\n";

prints--->$v1


benn600
User


Apr 28, 2005, 8:09 AM

Post #3 of 4 (815 views)
Re: [maximus] Variables [In reply to] Can't Post

I think that is what I want. If what you show there works, and I trust you, that will be great. I can't try it now because I'm not at home to work on the site, but thank you very much and I will be sure to try it tonight.
----------------------------------------------------------------------------
Wink http://www.ppcpathways.com/ Wink
Visit my new site devoted to reviewing the latest pocketpc products and news that I built in cgi-perl!


davorg
Thaumaturge / Moderator

Apr 29, 2005, 5:25 AM

Post #4 of 4 (809 views)
Re: [benn600] Variables [In reply to] Can't Post

What you are looking for is a feature known as "symbolic references". Perl supports this feature but as it is a very dangerous thing to do it is explicity disabled when you have "use strict" turned on (and you should _always_ have "use strict" turned on).

There is always a better way to do whatever it is you think you need smbolic references for. This probably involves using a hash, "real" references or more complex data structures.

Please don't do this. It will make your programs fragile, insecure and hard to maintain.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives