On Sun, Jan 18, 2004 at 09:53:56PM -0700 Bryan Harris wrote: > I've tried everything I can think of, but I feel like a 6th grader trying to > solve a 7th grade math problem: > > I'm trying to build a "pretty-fier" for any tab-delimited text file > (basically space-pad the columns so the decimals line up). I search through > the columns finding the longest field with and highest precision level for > each column, then create a format string for the printf command. The guts > of it looks like this: > > > ************************************** > $formatstr = ""; > $index = 0; > foreach (@lwid) { > $formatstr .= "%$lwid[$index].$lprec[$index]f".'\t'; > $index++; > } > substr($formatstr,-2,2) = ""; > $formatstr .= '\n'; > > open(FILE, ">$file$ext") || die("Couldn't create $file$ext: $!\n"); > > foreach (@content) { > @fields = split; > if (@fields) { printf FILE $formatstr, @fields; } > else { print FILE $_; } > } > > close(FILE); > ************************************** > > > ... but that "printf" spits out actual "\t" and "\n"s. How can I get the > printf to interpret those into tabs and newlines?
This is a typical data versus program problem. You have to give perl a hint that these are escapes and not literal strings. So turn your above foreach-loop into foreach (@lwid) { $formatstr .= "%$lwid[$index].$lprec[$index]f\t"; $index++; } Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>