----- Original Message ----- 
From: Me <[EMAIL PROTECTED]>
To: Christodoulou Demetris <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, May 03, 2001 10:26 AM
Subject: Re: How to implement Variable variable names?


> > Hi,
> > I am writing an application where i have to read
> > from a file variable names and variable values.
> > Is there is a way to use Variable Variables  with
> > the same way used in php?
> > For example:
> > $a = "hello";
> > $$a = "world";
> > where echo "$a ${$a}";  and  echo "$a $hello";  would output the same.
> > Thanks in advance,
> >    Demetris.
> 
> You can actually execute the above php code
> under perl and it will work!
> 
> (You need to add
> 
>     sub echo ($) { print shift }
> 
> at the start to let perl know what to do with
> echo, or you could just replace 'echo' with
> 'print'.)

But it is not gonna do what he wants.

> > $a = "hello";
$a contrain hello
> > $$a = "world";
$a contains a reference to a scalar which contrains "world"
---->  print "$a ${$a}"; will print the following :SCALAR-XXXXXX world
---->  print "$a $hello";  will print: SCALAR-XXXXXX 
cuz $hello has no value.

What you want to use are key value pairs like a hash.

my %values;
$values{hello} = "Goodday";
$values{world} = "earth";
print "$values{hello} $values{world}\n";

result will be:

Goodday earth



Reply via email to