To follow up on Jurgen Exner's critique, I present Xah Lee's version, and
then my rewritten version.
"Xah Lee" <[EMAIL PROTECTED]> writes:
> if (scalar @ARGV != 4) {die "Wrong arg! Unix BNF: $0
> \n"}
> $stext=$ARGV[0];
> $rtext=$ARGV[1];
> $infile = $ARGV[2];
> $outfile = $ARGV[3];
> open(F1,
Xah Lee wrote:
[...]
> In perl, similar code can be achieved.
> the following code illustrates.
>
> if (scalar @ARGV != 4)
Why scalar()? The comparison already creates a scalar context, no need to
enforce it twice.
> {die "Wrong arg! Unix BNF: $0
> \n"}
> $stext=$ARGV[0];
> $rtext=$ARGV[1];
OK. But please don't die throwing that string, or this post will lose
its educational purpose as it was meant to be.
--
http://mail.python.org/mailman/listinfo/python-list
© # -*- coding: utf-8 -*-
© # Python
©
© import sys
©
© nn = len(sys.argv)
©
© if not nn==5:
© print "error: %s search_text replace_text in_file out_file" %
sys.argv[0]
© else:
© stext = sys.argv[1]
© rtext = sys.argv[2]
© input = open(sys.argv[3])
© output = open(sys.argv[4],'w