At 14:22 +0200 07/02/2011, Shlomi Fish wrote:
Hi John,
a few comments on your code.
Actually, see perldoc perlrun - http://perldoc.perl.org/perlrun.html - by
giving -p and -i (untested) you can replace the contents of a file "in-place".
untested?! Why don't you test it before recommending it to others?
Now for some comments on your code.
You said that already.
> #!/usr/bin/perl
use strict;
Add "use warnings;" too.
I certainly will if I need them, Shlomi.
> my ($fin, $fout) = @ARGV;
It's great that you unpack @ARGV like that instead of using $ARGV[0], $ARGV[1]
etc. But please say something like $in_fn and $out_fn or something like that.
Thanks for the kudos. I fail to see how "something like $in_fn" is
any more or less obscure than $fin.
open FIN, $fin;
open FOUT, ">$fout";
1. Don't use bareword filehandles.
Don't just tell us; give us an example of an unbareword filehandle
and tell us why it's universally preferable.
2. Use three-args-open.
Ditto. If you want arguments you've come to the right place.
3. Always append or die.
Fair enough, I normally do even when, as in my example, I am not appending.
> while (<FIN>) {
To avoid $_ getting tempered with it's a good idea to use an explicit $line
variable.
You may think so and thousands of others may not. And while you're
at it, get yourself a decent mail program that does format=flowed.
<http://www.ietf.org/rfc/rfc3676.txt>
and since I'm subscribed to the list, I don't need a private copy of
the message either.
JD
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/