[Israel.pm] -i and more

Mikhael Goikhman migo at homemail.com
Mon Apr 19 05:24:31 PDT 2004


On 19 Apr 2004 13:56:45 +0300, Yossi.Itzkovich at ecitele.com wrote:
> 
> I need to write a scipt that gets:  inFileName outFileName oldStr  newStr
> 
> The script should be a simple one that replaces all occurances of oldStr
> with newStr  from inFileName, and save it in outFileName
> 
> I can do it in the long way or in the shorter (and much simpler ) way.

Why not to do it properly, i.e. work with stdin and stdout?

	perl -pe 'BEGIN { $old = shift || die; $new = shift || die; } s/\Q$old/$new/g' 2003 2004 <infile.txt >outfile.txt

If you absolutelly need a script with 4 parameters and not 2, write a
shell wrapper around this one liner:

	#!/bin/sh
	perl -pe 'BEGIN { $old = shift || die; $new = shift || die; } \
		s/\Q$old/$new/g' "$3" "$4" <"$1" >"$2"

or even a perl wrapper using system(). Left as an exercise.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list