From owner-freebsd-chat Mon Apr 17 20: 4:41 2000 Delivered-To: freebsd-chat@freebsd.org Received: from mailgate.originative.co.uk (mailgate.originative.co.uk [194.217.50.228]) by hub.freebsd.org (Postfix) with ESMTP id 7E44937BAF4 for ; Mon, 17 Apr 2000 20:04:34 -0700 (PDT) (envelope-from paul@originative.co.uk) Received: from originative.co.uk (lobster.originative.co.uk [194.217.50.241]) by mailgate.originative.co.uk (Postfix) with ESMTP id 26E771D15F; Tue, 18 Apr 2000 04:04:32 +0100 (BST) Message-ID: <38FBD0C0.F3385C66@originative.co.uk> Date: Tue, 18 Apr 2000 04:04:32 +0100 From: Paul Richards Organization: Originative Solutions Ltd X-Mailer: Mozilla 4.72 [en] (X11; I; Linux 2.2.12 i386) X-Accept-Language: en-GB, en MIME-Version: 1.0 To: Steve Price Cc: freebsd-chat@freebsd.org Subject: Re: Un*x scripting magic References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Steve Price wrote: > > On Tue, 18 Apr 2000, Paul Richards wrote: > > # > Then I have a multi-line (printable characters only) ASCII > # > text file containing the message that I'd like to replace > # > for %%MESSAGE%%. [1] Anyone have a neat little trick in > # > their bag-o-magic? I know the answer should be really > # > obvious but everything I've tried thus either hasn't worked > # > or was too convoluted. > # > # What's wrong with the obvious? > > It doesn't embed the text in the script. So everytime I > execute the script I have to re-read the file. Well in that case you need a pre-processor since there's no other way you can embed the information in the script. Write another perl script that reads your runtime script and does the substitution. In fact, it's not too hard assuming some constraints on the text (i.e. it shouldn't include %%.*%% strings) and that the placeholders are on a line of their own. It's not that much effort to make the whole thing more generic but the following few lines will probably do the job you want. my $SCRIPT = "the script to be preprocessed"; open(SCRIPT, $SCRIPT) || die; while (