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: mod_perl:
Please Help - Value not returned

 



sarathy
New User

Oct 23, 2006, 12:03 AM

Post #1 of 2 (7963 views)
Please Help - Value not returned Can't Post

$variable1="variable2";
$variable2="Actual value";

If I want to retrieve the string "Actual value" I will be giving :

$$variable1 (Value of(value of(variable1)). Normally this works. If mod-perl is on, it does not return any value.

I would really be grateful for any help :(
Jobs in India
Matrimonial
Real Estate in India


davorg
Thaumaturge / Moderator

Oct 23, 2006, 4:12 AM

Post #2 of 2 (7957 views)
Re: [sarathy] Please Help - Value not returned [In reply to] Can't Post

What you're doing here is using symbolic references. Symbolic references are a very bad idea and they should only be used very rarely.

They are such a bad idea that if you're programming with "use strict" turned on (and you should _always_ program with "use strict" turned on) then Perl turns symbolic references into compile time errors.

You very rarely have to use symbolic references (the only example I can think of is to alter the symbol table). You'll be far better off changing your code to use a hash instead.


Code
my %vars; 
my $variable1 = 'variable2';
$vars{$variable1} = 'Actual value';

print $vars{$variable1};


--
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