[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] exchanging data (again)



On Mon, 10 Jul 2000 11:56:58 +0200, Allan Juul wrote:

>can anyone show me a very simple working example if i have
>these two files:
>thanks 
>allan
>
>
>1.txt:
>
>hello
>world
>here is the old date
>today is the 9th of july
>more stuff
>
>2.txt:
>
>9
>10
>11
>12
>
>i just need to know the basic procedure of how to get the figure "10" from
>2.txt into the fourth line of 1.txt (so it reads: "today is the 10th of
>july")

I think I speak for everybody, if I say that your requirements are not
clear at all. What do you want? How can we know that you want the "10"
from the second file? How should we recognize the location to put the
replacement in the first file?

And do you want to replace the oruiginal contents of the first file, or
do you want to print a modified version (e.g. send to browser), and
leave the original file alone?

If you want to replace the original file, try something like:

	#! perl -i.bak
	while(<>) {
	    s/(\d+)/$1==9?'10':$1/ge;
	}

But I think what you really want, is a template mechanism. There are
already lots of template modules available on CPAN, but you can still
roll your own. All you need is a recognizable pattern, from which you
can extract a "variable" name, look it up in a hash, and replace the
original thing with the value from the hash, in a s///g statement.

-- 
	Bart.

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org