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: Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Dec 2006 12:40:23 -0800
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"?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
.
- Follow-Ups:
- References:
- Prev by Date: Localized STDOUT
- Next by Date: regex help please
- Previous by thread: 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: Re: FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file?
- Index(es):