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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading and changing file content

Status
Not open for further replies.

mikilh

Programmer
Feb 22, 2008
2
US
I'm new to perl. I would like to read a text file and enclose each line in brackets (just for the heck of it). I can read the file and add stuff to the beginning of each line, but I can't seem to get stuff added to the end of each line.

For example,
this is a line of text

I want
<< this is a line of text >>

I get
>> this is a line of text

The text I want at the end is overwriting the beginning.

Can someone throw me a bone?
 
#!/usr/bin/perl

open (example, "tablemetadata.txt") or die ("Could not open file. <br> $!");

while ($text=<example>)
{
chomp($text);
next if $text =~ /^\s*$/;
$text=~s/^\s+//;
$text=~ s/^\s+//;
print "<< $text >>$/";
}
close (example);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top