Hi Meir,

Wow. I've never seen Perl formats being used in RL (or even mentioned anywhere outside of the Perl documentation)!

The last paragraph of the perlform document (perldoc perlform) says:


> "Within strings that are to be displayed in a fixed length text field, each control character is substituted by a space."


I think that because the main point of formats is to produce fixed-width output, characters like tabs that have a variable-width representation are problematic.


Does using format/write in this case give you anything that "print" doesn't provide?


- Dotan


On 08/02/2011 02:31 PM, Meir Guttman wrote:

Hi all!

I use "format" and "write" for a long time now. Very satisfied with the results.

But today I tried to "write" a Tab-Separated-Values record. Strange! All tabs where converted to spaces!

Should I use the write/format at all (i.e. is it deprecated?)

Is there a way to force the write/format to preserve tabs?

Meir

Here is a small script that does it:

# -------------------------------

use strict;

use warnings;

my $message = "One\tTwo\tThree\tFour\tFive";

open my $log_fh, ">:encoding(utf8)", "TSV_log.txt";

format LOG_FORMAT =

~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$message

.

select($log_fh);

$~ = "LOG_FORMAT";

write;

close $log_fh;

# -------------------------------

Its output is (no tabs, just spaces):

  One Two Three Four Five¿


_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to