[EMAIL PROTECTED] wrote:
On Aug 9, 6:46 am, [EMAIL PROTECTED] (Chas Owens) wrote:
On 8/8/07, Jeff Pang <[EMAIL PROTECTED]> wrote:
snip> perl -pi -e '$i++;s/^.*$/something/ if $i==10' your_file
snip
There is no need to keep track of the number of lines with a separate
variable. Perl already does this with the $. variable. Also, a regex
that replaces everything is pointless, just assign to $_.
perl -pi -le '$_ = "something" if $. == 10' your_file
So if this was in a script rather than a oneliner how would it work?
I was playing and can not get it to work in an actual test script.
Not surprising since it's not correct.
perl -pi -e '$_ = "something\n" if $. == 10' your_file
See `perldoc perlrun` for a description of the command line switches.
As a script:
#!/usr/bin/perl
use strict;
use warnings;
while(<>){
if( $. == 10 ){
print "something\n";
}else{
print;
}
}
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/