in reply to Re: Resolving scalars in a scalar
in thread Resolving scalars in a scalar

So after mindlessly fiddling with the eval statement, I came up with the following;
my $alpha = "A"; my $delta = "D"; my $test = "$delta and $alpha"; eval "\$test = \"$test\""; print "$test";
Is that... right?

Is it fair to stick a link to my site here?

Thanks for you patience.

Replies are listed 'Best First'.
Re: Re: Re: Resolving scalars in a scalar
by Roger (Parson) on Oct 31, 2003 at 04:03 UTC
    Ummm, because your $test is quoted inside double quote, your $test = "D and A" even before you go into the eval, so the eval had no effect.

    Change the code slightly as follows -
    my $alpha = "A"; my $delta = "D"; my $test = '$delta and $alpha'; eval "\$test = \"$test\""; print "$test";
    and yes, it will work this time, because the code is equivalent to -
    my $alpha = "A"; my $delta = "D"; my $test = '$delta and $alpha'; $test = "$delta and $alpha"; print "$test";
    Where the variable $test inside double quote " " has been expanded by the perl interpreter to the value of $test before going into eval