--- Begin Message ---
In a message dated 7/27/2005 12:48:35 P.M. Eastern Standard Time,
[EMAIL PROTECTED] writes:
> From: Greg [mailto:[EMAIL PROTECTED] > > >
> Sorry if this has been answered before but I am in a quandary.
> > > > I am trying to get the contents of a variable when
that variables name > > is itself in a different variable. For
example: > > > > $database_name =
"Greg"; > > $text = "database_name"; >
> $value = "\$" . $text; >
> print $value; > > > > I need to
have 'Greg' printed not $name; > > > > Is this possible?
Seems I've seen this before but can't recall. > > Thanks for all your
help. > > This is called a "Symbolic Reference". You do it
like this: >
assuming that symbolic references have been disabled by invoking
use strict;
or
use strict 'refs';
earlier in the script (always a good idea), symbolic refs must be
temporarily re-enabled.
(``use strict;'' additionally requires that all package names be fully
qualified in form ``$full::package::name = 'something';'' or ``our $name =
'something';'')
> > $database_name = "Greg"; # must
be ``our $foo = 'bar;'' if ``use strict;'' > $text
= "database_name"; no strict 'refs'; #
re-enable symbolic refs
> $value = $$text; # can also be ${$text}
for (possibly) better readability use strict
'refs'; # disable symbolic refs again
> print $value; > > Bowie
hth -- bill walters
|
--- End Message ---
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs