Hi Joseph:

Thanks very much for the feedback.  Unfortunately for me, I've been 
totally swamped with tasks totally unrelated to Perl.  I've had virtually 
no time to spend on this.  I hope to have time this weekend to look at 
Perl related activities (my wife may have other thoughts about that 
however :-))

Anyway, here is the context of what I was trying to learn how to do.

Basically, I wanted to know how to put a receipient's name into a canned 
letter.  Like this.

$name = "Joe Blow"

The canned letter template:

        Dear $name:

        Your are a very nice person.

After running the program, the letter would be sent like this:

        Dear Joe Blow:

        You are a very nice person.

I'll try to cleanup & send the actual code I use for this.  After seeing 
the actual code, I would be very interested in getting your expert advice 
and opinion.  If indeed I'm not doing this in a proper way, I will 
certainly want to correct that. 

Thanks again for providing the feedback.  I greatly appreciate your taking 
the time to help in advancing my Perl knowledge.  I just wish I had more 
time to spend with Perl.  It's such a fun language !

- Stuart

 



 



"R. Joseph Newton" <[EMAIL PROTECTED]> 
01/30/2004 12:50 AM

To
[EMAIL PROTECTED]
cc
[EMAIL PROTECTED]
Subject
Re: How to put a variable value into a text file






[EMAIL PROTECTED] wrote:

>
> Here's what it prints:  My name is $name.
>
> Here's the testmessage.txt file:  My name is $name.

Hi Stuart,

I think that there is a conceptual problem here.  This really isn't the
appropriate way to get modular code into a program.  Programming would be 
a
dangerous business indeed if our programs automatically interpolated 
variable
names encountered in text data.

The techncal concerns are relatively minor compared to the conceptual
problems.  I would recommend against pursuing this path of inquiry, 
because
the mixing of data and program code is inherently a seed of error and 
system
instability.  It also can be an easy route for subverting system security.
Data and program structures should not be mixed without compelling reason, 
and
a high-end understanding of the potential consequences.  New students of
programming should avoid it entirely, IMHO.

Can you think of a real-world situation where you would want to put 
program
code in a data file?  If you want modular functionality, Perl does have 
some
very approachable protocols for creating packages of such functionality,
including the option of creating instantiable objects to reflect 
real-world
concepts.  For this, you might want to start with:

perldoc perlmod
perldoc perlobj
but first, for necessary background, read
perldoc perlref
or at least
perldoc perlreftut

Use the language features designed for linking functions, though. 
Hand-hcking
mixed code and data will only get you in trouble.

Joseph


Reply via email to