Home: Perl Programming Help: mod_perl:
Please Help - Value not returned



sarathy
New User

Oct 23, 2006, 12:03 AM


Views: 13725
Please Help - Value not returned

$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


Views: 13719
Re: [sarathy] Please Help - Value not returned

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