in reply to Using '/r' with '~~ $var' in format

I would suggest changing you approach, I think you are stuffing too much in that one line. You are doing format's job, when you try to control the layout with your own \r and \n's.

#!/usr/bin/perl -w use strict; my $last_line_label = 'IMPRESSION/PLAN: '; my $line = 'I discussed otitis media with her but since her ear +s are normal today, we do not need to do anything with them.'; my $blank_line = '_____________________________'; my $sig = 'Marcus Welby, M.D.'; my $prep_by = 'MW/bnj'; format FLDFMT = @<<<<<<<<<<<<<<<<^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $last_line_label, $line ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $line @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $blank_line @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $sig @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $prep_by . $~ = 'FLDFMT'; write;



grep
Mynd you, mønk bites Kan be pretti nasti...

Replies are listed 'Best First'.
Re: Using '/r' with '~~ $var' in format--"formats on the fly"
by ff (Hermit) on Nov 01, 2002 at 22:11 UTC
    Well, you are right that a practical answer is to change the approach. But there's stuff behind the question that you can't see ;-)

    Quoting Larry/The Camel Book,
    The truly desperate can generate their own format on the fly...

    When my program runs, I won't know what is in the $line string, i.e. it won't always be data types like sig and prep_by. (And I also build the FORMAT definition in a subroutine but I thought that would distract from my question.) Practically speaking, the data will usually be paragraphs with newlines for separators, and it's these blank lines that I particularly want respected. But as my Version D shows, I'd really like any newline within $line to be respected.

      What about ditching format? It sounds like your needs will be surpassing what format will do easily (and more importaintly if you do pull it off, it sounds like a maintainence nightmare).

      Template Toolkit sounds like a great fit for you. TT is designed to template any job not just HTML (as long as you don't need pagination)



      grep
      Mynd you, mønk bites Kan be pretti nasti...
        It looks like Template Toolkit will be useful for the next stage in my process in which I officially present the data and the user doesn't need it in Word. Thanks for the tip. For this particular stage, I just need to create a rough draft and using 'format' statements will be sufficient (esp. since I've already written the code :-) So the question remains, how might I use \r to achieve embedded newlines that will be respected by '~~ $var' lines within a format statement?