Home > Archive > PERL Beginners > October 2007 > about formatted text
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
about formatted text
|
|
| Camotito 2007-10-27, 7:00 pm |
| Hello!
I am using perl on msys in a windows operating system.
I was manipulating a file with .TAB extension. This is a file with 10
(or so) columns separated by tabs.
I store each line in an array, after doing modifications to a couple
of fields I print the array in another file using this line :
print FHO "@values\n";
The program I am using (that is running over windows) can only read
the first line in the modified file. When I open the modified file
with notepad I see an square at the end of each line.And all the lines
are in one line.
The original .TAB file doesn't show that square character, and the
lines appear one below each other.
Wich character should I use to have a file similar to the original
one? And also, how can I print an array so there are tabs between the
different fields, instead of a single space?
Thanks!
| |
| Rob Dixon 2007-10-27, 7:00 pm |
| camotito wrote:
> Hello!
>
> I am using perl on msys in a windows operating system.
>
> I was manipulating a file with .TAB extension. This is a file with 10
> (or so) columns separated by tabs.
> I store each line in an array, after doing modifications to a couple
> of fields I print the array in another file using this line :
> print FHO "@values\n";
>
> The program I am using (that is running over windows) can only read
> the first line in the modified file. When I open the modified file
> with notepad I see an square at the end of each line.And all the lines
> are in one line.
> The original .TAB file doesn't show that square character, and the
> lines appear one below each other.
> Wich character should I use to have a file similar to the original
> one? And also, how can I print an array so there are tabs between the
> different fields, instead of a single space?
The square character will be a non-printable character, possibly in your
array data or maybe because the newline character isn't being handled
properly. Try just
print FHO "---\n";
and see whether that comes out ok, or if it also has a square at the end.
To print your array with tab characters between the elements you can do
either
print join("\t", @values), "\n";
or
{
local $" = "\t";
print "@values\n";
}
HTH,
Rob
| |
| Daniel Kasak 2007-10-28, 4:00 am |
| On Sat, 2007-10-27 at 14:18 +0000, camotito wrote:
> The program I am using (that is running over windows) can only read
> the first line in the modified file. When I open the modified file
> with notepad I see an square at the end of each line.And all the lines
> are in one line.
For a Windows newline, try:
\r\n
instead of just:
\n
Dan
| |
| Gunnar Hjalmarsson 2007-10-28, 4:00 am |
| camotito wrote:
> I am using perl on msys in a windows operating system.
>
> I was manipulating a file with .TAB extension. This is a file with 10
> (or so) columns separated by tabs.
> I store each line in an array, after doing modifications to a couple
> of fields I print the array in another file using this line :
> print FHO "@values\n";
>
> The program I am using (that is running over windows) can only read
> the first line in the modified file. When I open the modified file
> with notepad I see an square at the end of each line.And all the lines
> are in one line.
Did you possibly modify the file in a *nix environment? In that case,
"\n" represents \012, while the newline symbol on Windows is \015\012.
Read more about this in "perldoc perlport".
> The original .TAB file doesn't show that square character, and the
> lines appear one below each other.
> Wich character should I use to have a file similar to the original
> one? And also, how can I print an array so there are tabs between the
> different fields, instead of a single space?
Again, if you are doing the mods on *nix, this might be what you want:
print FHO join("\t", @values), "\015\012";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Camotito 2007-10-28, 10:00 pm |
| Thanks for the help. Yes, I was modifying the file in a unix
enviroment (msys). Printing \r\n instead of \n solve the problem.
Wikipedia has a nice article about this issue with some perl code for
modifying/adapting line-breaks between different operating systems :
http://en.wikipedia.org/wiki/Newline
Regards
Camotito
On Oct 27, 3:18 pm, camot...@gmail.com (Camotito) wrote:
> Hello!
>
> I am using perl on msys in a windows operating system.
>
> I was manipulating a file with .TAB extension. This is a file with 10
> (or so) columns separated by tabs.
> I store each line in an array, after doing modifications to a couple
> of fields I print the array in another file using this line :
> print FHO "@values\n";
>
> The program I am using (that is running over windows) can only read
> the first line in the modified file. When I open the modified file
> with notepad I see an square at the end of each line.And all the lines
> are in one line.
> The original .TAB file doesn't show that square character, and the
> lines appear one below each other.
> Wich character should I use to have a file similar to the original
> one? And also, how can I print an array so there are tabs between the
> different fields, instead of a single space?
>
> Thanks!
| |
|
|
|
|
|