On 8/12/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote:
snip
> >> 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
>

Umm, what exactly is "not correct"?  The use of -l removes the need to
add "\n" in the assignment to $_.  You can make an argument that it is
inefficient to be calling chomp and join for every line of the file,
but that doesn't make it wrong.

[EMAIL PROTECTED]:~/Desktop/watch$ cat test
1
2
3
4
5
6
7
8
9
0
1
[EMAIL PROTECTED]:~/Desktop/watch$ perl -pi -le '$_ = "something" if $. == 10' 
test
[EMAIL PROTECTED]:~/Desktop/watch$ cat test
1
2
3
4
5
6
7
8
9
something
1

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to