Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put a tag at the end of the line after reading a file

Status
Not open for further replies.

Ramnarayan

Programmer
Jan 15, 2003
56
US
Hi,

I have a unique situation. WHen I open a txt file, I know that the end of the file has to have a closing tag. So that means when I read the file, I want to automatically go to the end of the line and put the tag as below:

Line 1: this is a
Line 2: test file and
Line 3: has many lines
Line 4: ending with the last line.

Now when I open this file, I want to be able to jump to line number 4 or the last line of any file, and put the tag </text> by default. How can I accomplish this using File I/O? Note that the input file can have any number of lines. But always the last line should be picked out and at the end of this line has to have a tag </text> as below:

Line 4: ending with the last line. </text>.

As usual, thanks for your quick responses.
 
I don't know about using a specific module for doing it.. but
open(FILE, "/path/to/file") or die "can't open /path/to/file:$!\n";
@file = <FILE>;
chomp @file;
close file;
$file[$#file] .= "</text>";

THen you can just write it back out

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
use the Tie::File module.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
How do I use a Tie:File module. ANy pointers will be great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top