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

Spacing problems in I/O 1

Status
Not open for further replies.

titanandrews

Programmer
Feb 27, 2003
130
0
0
US
Hi,
I have a program which reads all the lines of a C++ source file into an array, like this:
Code:
@lines = <MY_CPP_FILE>;
Then I display the lines to the console like this:
Code:
foreach(@lines)
{
   print $_;
}

The problem is that somewhere I am getting double spaces on all the lines that contain spaces in front of the line. For example, if this were the C++ file I am reading.

Code:
bool MyClass::isTrue()
{
   return true;
}

The display on the console will look like this:
Code:
bool MyClass::isTrue()
{
       return true;
}

Notice the extra 4 spaces. This is double what I originally had. Does anyone know what is causing this, and how to correct it?

many thanks,

Barry
 
Are you sure that there are spaces?
I think this are tabs and the tabsize is different.
regards
Chris
 
Yep, you're right! I solved the problem by using the Text::Tabs module like this:

Code:
use Text::Tabs;
$tabstop=4;
@lines = expand(@lines);

thanks,

Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top