in reply to Please help me understand string eval better
eval "$$var$transf"
eval $$var.$transf
These two expresions are essentially the same. $$var.$transf is simply an explicit string concatenation that would be done implicitly in a "$$var$transf" double-quotish interpolation. (Update: The concatenation/interpolation is done at run time, and then the resulting string is eval-ed.)
eval '$$var'.$transf
This is a bit different. A literal string '$$var' (the dollar signs are part of the literal string) is explicitly concatenated with the stringization of whatever is in the $transf scalar. (Update: Again, the concatenation is done at run time and the resulting string is eval-ed.)
Try experimenting with these string expressions — without the eval part until you're sure what's going on!
Update 1: Note that $$var is the dereference of a reference to a scalar: $var holds a reference to some other scalar.
Update 2: Some examples:
Once again, experiment — it's fun and easy!c:\@Work\Perl\monks>perl -wMstrict -le "my $foo = 'rm '; my $var = \$foo; my $transf = '-R *'; ;; print qq{A: >$$var$transf<}; print 'B: >', $$var.$transf, '<'; print 'C: >', '$$var'.$transf, '<'; " A: >rm -R *< B: >rm -R *< C: >$$var-R *<
Update 3:
... what gets done ... at compile time ...That's the eval BLOCK form. It's compiled at... well, compile time, and must be syntactically correct. (The eval EXPR form need not be.) Please see the docs for more info, get back to us with any specific questions.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Please help me understand string eval better
by perltux (Monk) on Jun 13, 2017 at 03:25 UTC | |
by huck (Prior) on Jun 13, 2017 at 03:40 UTC | |
by AnomalousMonk (Archbishop) on Jun 13, 2017 at 03:56 UTC | |
by perltux (Monk) on Jun 13, 2017 at 04:19 UTC | |
by shmem (Chancellor) on Jun 13, 2017 at 06:38 UTC |