tobold.org

correct • elegant • free

△ comp.lang.perl △

◅ SIG{'INT'}

fork() and SysV Process Groups in perl question ▻

Variable Substitution

In article <32EF53BB.217A@newbridge.com>,
Jason Matheson  <jmathes@newbridge.com> wrote:
>              How can I place a scalar in place of '%ENV' in the 'keys'
>command, that contains the name of the associative array (ex. %ENV,
>%another, %andanother) I want printed. In other word can I force
>substitution of the scalar before the 'keys' command uses it? I know I
>can do such a thing in TCL but how do I do it in Perl.

To do what you're literally asking for, you need `eval'.

For example...

    $ perl
    %formal = qw(hi hello bye goodbye);
    $n = <STDIN>;
    print join ' ', eval "keys $n";
[Hit end of file here]
    %formal
    bye hi

However, I suspect that the language feature you're really after is
references.  These are explained in the perlref(1) man page.

Tim.
--
Tim Goodwin   | "A language needs both intestines and guts." -- Larry Wall

Original headers:

From: tim@pipex.net (Tim Goodwin)
Newsgroups: comp.lang.perl.misc
Subject: Re: Variable Substitution (not string substitution)
Date: 29 Jan 1997 17:18:27 GMT
Organization: UUNET PIPEX
Message-ID: <5co0p3$6l3@join.news.pipex.net>
References: <32EF53BB.217A@newbridge.com>

△ comp.lang.perl △

◅ SIG{'INT'}

fork() and SysV Process Groups in perl question ▻