Re: FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file?
- From: brian d foy <brian.d.foy@xxxxxxxxx>
- Date: Fri, 29 Dec 2006 10:18:39 -0800
In article <281220061240239668%jgibson@xxxxxxxxxxxxxxxxx>, Jim Gibson
<jgibson@xxxxxxxxxxxxxxxxx> wrote:
In article <ngkd64-fr8.ln1@xxxxxxxxxxxxxxxxxxx>, PerlFAQ Server
<brian@xxxxxxxxxxxxxx> wrote:
5.2: How do I change, delete, or insert a line in a file, or append to the
beginning of a file?
To change only a particular line, the input line number, $., is useful.
Use "next" to skip all lines up to line 5, make a change and print the
result, then stop further processing with "last".
while( <$in> )
{
next unless $. == 5;
s/\b(perl)\b/Perl/g;
print $out $_;
last;
}
This example results in a single line being written to the output file.
Is that is what is intended by "To change only a particular line"?
I don't think that's what's intended. Often, the code is just part of a
program and you have to fill in the rest, but in this case I can't see
what you'd put before this snippet to make it work out right.
I'll add this of my list of things to update.
Thanks :)
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- Prev by Date: Debug question
- Next by Date: Re: Debug question
- Previous by thread: Re: FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file?
- Next by thread: Localized STDOUT
- Index(es):