Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: keeping the text-format when using write Keywords: write Message-ID: <8816@jpl-devvax.JPL.NASA.GOV> Date: 21 Jul 90 02:30:36 GMT References: <1104@nixsin.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 102 In article <1104@nixsin.UUCP> koerberm@nixsin.UUCP (Mathias Koerber) writes: : I try to do something like this: : : format SPOOL = : @<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< : $time, $description, $result : ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< : $description, $result : . : : then, when it comes to show an error, I do this: : : $result = <<"EOT"; : There was an error in function xxxxx. This may be due to different reasons : a) ..... : b) ..... : c) ..... : : remedies: : a)... : b)... : c)... : EOT : write SPOOL; : : : My problem is, that write squeezes as much as possible into the text, getting : rid of my nice indents, newlines etc. : I tried setting : $: = "\n"; : so that write has to break at the newline, without success. : I don't care if it breaks ALSO where the line is full, but 'd like it to : break on newlines and keep tabs whenever it finds them. : : Is there any way to do this? Well, you could do it something like this: format SPOOL = @<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $time, $description, $result = $result || shift(@result) ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description, $result = $result || shift(@result) . @result = split(/\n/,<<"EOT"); There was an error in function xxxxx. This may be due to different reasons a) ..... b) ..... c) ..... remedies: a)... b)... c)... EOT for (@result) { s/\t/ /; s/^$/./; } write SPOOL; Note that it turns a blank line into a . to fool the ~~. Otherwise it doesn't print out the whole array. You could also use a subroutine: format SPOOL = @<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $time, $description, $result = &load ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description, $result = &load . @result = split(/\n/,<<"EOT"); There was an error in function xxxxx. This may be due to different reasons a) ..... b) ..... c) ..... remedies: a)... b)... c)... EOT sub load { $result .= shift(@result) if $result eq ''; $result =~ s/\t/ /g; # shorten tabs to 4 spaces $result = '.' if $result eq '' && @result; $result; } write SPOOL; Or something like that. You've still got the problem that you might want to ignore some newlines and not others. You could in fact just load up an array the way you want, with the lines split just where you want, and then just use regular @ fields with a shift. Nothing says you have to use ^ fields just because they're there, if they don't do what you want. Larry