Executing perl variables
Brett Worth
brettw at cray.com.au
Wed Dec 26 12:26:10 EST 2001
On Wed, 26 Dec 2001, Michael Still wrote:
> I have a desire to execute code embedded in perl variables. For instance,
> let's say that:
>
> y=4;
> $x="y++";
>
> << magic execute thing >>
>
> Then y should be 5.
>
> Does anyone have any idea how to do this?
#!/usr/bin/perl
$y = 4;
$x=eval('$y++');
print "$y\n";
Is that what you want?
Of course $x will be 4 unless you do ++$y.
Brett
/) _ _ _/_/ / / / _ _//
/_)/</= / / (_(_/()/< ///
Cray Australia.
brettw at cray.com +61 2 6295 4023
PGP: 1024R/27EB604F 22A9 A85A 22BD 496B 2443
35E5 46F7 0712 27EB 604F
More information about the linux
mailing list