Hi Dotan, thanks! It is amazing how I miss important sentences! (I was searching for "tab" in that man page. BTW, tabs does other weird things when strings are longer than the format element they are sent to.)
Of course I can use "print", but the "format"/"write" makes things easier for one of my applications. Thanks! Meir _____ From: [email protected] [mailto:[email protected]] On Behalf Of Dotan Dimet Sent: Tuesday, August 02, 2011 4:34 PM To: Perl in Israel Subject: Re: [Israel.pm] and Tab-Separated-Values 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 <http://www.mailscanner.info/> MailScanner, and is believed to be clean. No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.901 / Virus Database: 271.1.1/3804 - Release Date: 08/01/11 21:34:00
_______________________________________________ Perl mailing list [email protected] http://mail.perl.org.il/mailman/listinfo/perl
