**FORMAT Formatting columns/pages 
Author Message
 **FORMAT Formatting columns/pages

I am writing a program in which I am trying to use format a page out.  I
need a
page break after the limit of columns has been reached.  Example:

***This:
                                     Column  Column Column Col.      Col.
Col.     Col.
Col.    Total   Avg.
                                        Title      Title     Title
Title      Title     Title     Title
Title    Title    Title
----------------------------------------------------------------------------
---
last-name,  first-name         ##        ##        ##        ##        ##
##        ##
--------------------
##        ##       ##
last-name,  first-name         ##        ##        ##        ##        ##
##        ##
##        ##       ##
...
...

***Needs to be this:
                                     Column  Column Column Col.      Col.
Col.     Col.
                                        Title      Title     Title
Title      Title     Title     Title
----------------------------------------------------------------------------
---
last-name,  first-name         ##        ##        ##        ##        ##
##        ##
last-name,  first-name         ##        ##        ##        ##        ##
##        ##
...
...
<break after # of people>
                                      Col.    Total   Avg.
                                      Title    Title    Title
----------------------------------------------------------------------------
---
last-name, first (cont'd)    ##       ##       ##
last-name, first (cont'd)    ##       ##       ##
...
...

-->The number of columns (cols) is variable from one input file to the next.

Now, I am trying to use format to accomplish this.  I know that format makes
it easy to do a page break, but I basically need to do a horizontal page
break to accomplish this.  Does anyone have a method that would accomplish
what I am trying to do, or know of a format option to do this?  I fear that
I'm going to have to break down and use loops and parse it down, but I would
assume that perl would simplify this report, unlike C.

Thanks much!

George



Wed, 18 Jun 1902 08:00:00 GMT  
 **FORMAT Formatting columns/pages

Quote:

>  perl -014 -lpe '$x=join "\n", /^.{0,80}/mg; s/^.{80}//mg; print $x'

>It bugs me to have to write the REx twice.  Golf, anyone?

Well, you have two different RE there, not just one RE twice.  As for golf,
instead of landing on the $x island, you can just give a good hard swing and fly
right by it:

    perl -014ple 'print join "\n", /^.{0,80}/mg; s/^.{0,80}//mg'

The following avoids writing the same RE twice:

    perl -014ple 's/^.{0,80}/!printf"$&\n"/gem/s/^/\f/'

--
Neko



Wed, 18 Jun 1902 08:00:00 GMT  
 **FORMAT Formatting columns/pages
[posted & mailed]

Quote:

> -->The number of columns (cols) is variable from one input file to the next.

> Now, I am trying to use format to accomplish this.  I know that format makes

If the number of columns is variable then you probably don't want to use
format.  Sure, you can play with formline, but printf will serve you
better in this case.

Quote:
> it easy to do a page break, but I basically need to do a horizontal page
> break to accomplish this.  Does anyone have a method that would accomplish
> what I am trying to do, or know of a format option to do this?  I fear that

There is no format option for this.

perldoc perlform

If you did only need one format then one way to do this would be to make
your format as wide as it needs and then run the output through a filter
that moved stuff on the right to a new page.

  perl -014 -lpe '$x=join "\n", /^.{0,80}/mg; s/^.{80}//mg; print $x'

It bugs me to have to write the REx twice.  Golf, anyone?

Quote:
> I'm going to have to break down and use loops and parse it down, but I would
> assume that perl would simplify this report, unlike C.

Perl will still simplify it compared to C.

--
Rick Delaney



Wed, 18 Jun 1902 08:00:00 GMT  
 **FORMAT Formatting columns/pages

Quote:

> instead of landing on the $x island, you can just give a good hard swing and fly
> right by it:

>     perl -014ple 'print join "\n", /^.{0,80}/mg; s/^.{0,80}//mg'

Hmph, should've seen that.

Quote:
> The following avoids writing the same RE twice:

>     perl -014ple 's/^.{0,80}/!printf"$&\n"/gem/s/^/\f/'

                                                ;
Cute, thanks, but no need to obfuscate.    --->>^

--
Rick Delaney



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Columns from a format definition?

2. Multi-column format?

3. Formatting output in columns:

4. Format a one line file to get two columns

5. column format -easier way of doing it

6. Tricky column formatting/space removing question

7. multi column format

8. ANNOUNCE: IO::Format 0.02 (perl formats, object oriented, footers)

9. Printing in format statments using e/g format

10. Converting from ctime format to time_t format

11. Perl manual (Emacs info-mode format?, NG format)

12. PERLFUNC: format - declare a picture format with use by the write() function

 

 
Powered by phpBB® Forum Software