markwild has asked for the wisdom of the Perl Monks concerning the following question:
What I'd like is for the message to print as "Hello Larry Wall", but what I get is "Hello". Eval doesn't seem to work the way I would expect it to. (So I must be expecting incorrectly, too!) I've tried this:$message = "Hello $name\n"; #. . . other code that does unrelated stuff . . . $name = "Larry Wall"; print $message;
I still just get "Hello" back. And then I got to thinking that maybe I got just the "Hello" because $name was already substituted, and by this time only "Hello" exists in the string (without the $name). So, I tried to declare $message with single quotes thusly:$message = "Hello $name\n"; #. . . other code that does unrelated stuff . . . $name = "Larry Wall"; print eval $message;
And that didn't work either. I got nuthin.$message = 'Hello $name\n'; #. . . other code that does unrelated stuff . . . $name = "Larry Wall"; print eval $message;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Postdefining scalars
by japhy (Canon) on Mar 27, 2001 at 04:11 UTC | |
|
Re: Postdefining scalars
by japhy (Canon) on Mar 27, 2001 at 04:14 UTC | |
|
Re: Postdefining scalars
by petral (Curate) on Mar 27, 2001 at 11:37 UTC | |
|
Re: Postdefining scalars
by little (Curate) on Mar 27, 2001 at 12:40 UTC |