BigJerry has asked for the wisdom of the Perl Monks concerning the following question:

Hi All:

I'm trying to switch from using old-style formats to those provided by Perl6::Form. Simple reports seem to work fine, but now I'm trying to convert several scripts that retrieve a list of column values from MySQL and then print a formatted list of the returned results. Thebse can be several pages in length, so I was trying to use the 'page' and 'header' options to print headings at the top of each page, breaking the list at a defined page size. From the documentation, I can't put this together so it works. The script basically prints inside a loop which fetches each selected row from the database. If I try

print form { page => { length => 10, number => 1, feed => "\f", footer => "\n", header => { first => "================================ +=====================================\n" . "| xxxxxxxxxxxx +xxxxxxxxxxxxxxxx |\n" . "| xxxxxxxxxx +xxxxxxxxxxxx |\n" . "| + |\n" . "| List +of Players |\n" . "|=============================== +====================================|\n" . "|Last |First + |MI|Suffix|Nickname | ID|\n" . "|_______________________________ +____________________________________|", other => "================================ +=====================================\n" . "| List +of Players |\n" . "|=============================== +====================================|\n" . "|Last |First + |MI|Suffix|Nickname | ID|\n" . "|------------------------------- +------------------------------------|", } } };

before the loop and then use another 'print form' inside the loop to print the values from each row, I get the first page headers followed by enough blank lines to fill a page, then the normal list of rows. Not what I wanted. If I try putting the page/header information in the single 'print form' inside the loop, I get get the first page header pluse the row information for each and every row. Also not what I want.

Obviously, I'm misunderstanding something, but what? I searched the web for eamples of using Perl6::Form, seeking understanding, but found none.

I would be eternally appreciative of any help you could offer. Thanks.

Replies are listed 'Best First'.
Re: Headings in Perl6::Form
by TomDLux (Vicar) on Aug 26, 2011 at 03:21 UTC

    I haven't used the Perl6::Form, but the way forms work, generally, is you define how components work, and then there's some method or some print modifier, which sends your print output to the form.

    I think at the moment you are defining a form which has a header but no body, and a different form which has a body and no header, or the standard header.

    I would start with the middle chunk, and then gradually add the headers and footers in after.

    Update ... Did you read the DOC in the module file? Type perldoc Perl6::Form in an xterm window, or browse to the CPAN documentation page

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re: Headings in Perl6::Form
by Anonymous Monk on Aug 26, 2011 at 06:29 UTC
    Like so:
    #! /usr/bin/perl -w use strict; use 5.010; use Perl6::Form; my @last = qw(Smith Jones Wright Wong Evans McFee Ho Nuygen Willians H +owlett Jones Peters Milford Tam Lam Soma Egon Wilson); my @first = qw(Jim Jack Wendy Lee Bo Lenord Jan Dana Lindy Kyle Nora J +ane Bill Woo John Mick Lazlo Jenna); my @mid = qw{A B C D E F G H I J K L M N O P Q R}; my @suf = ("") x 18; my @nick = qw(Jim Jack Wendy Lee Bo Lenord Jan Dana Lindy Kyle Nora Ja +ne Bill Woo John Mick Lazlo Jenna); my @ID = 1..18; print form { page => { length => 10, number => 1, feed => "\f", footer => "\n", header => { first => "================================ +=====================================\n" . "| xxxxxxxxxxxx +xxxxxxxxxxxxxxxx |\n" . "| xxxxxxxxxx +xxxxxxxxxxxx |\n" . "| + |\n" . "| List +of Players |\n" . "|=============================== +====================================|\n" . "|Last |First + |MI|Suffix|Nickname | ID|\n" . "|_______________________________ +____________________________________|", other => "================================ +=====================================\n" . "| List +of Players |\n" . "|=============================== +====================================|\n" . "|Last |First + |MI|Suffix|Nickname | ID|\n" . "|------------------------------- +------------------------------------|", } } }, "| {]]]]]]]]]]]]]]]]} | {]]]]]]]]]]]]]]]]} |{}| {II} | {]]]]]]} | +{} |\n", \@last, \@first, \@mid,\@suf, \@nick, \ +@ID;

      Thanke, this helps greatly! Now I run into another problem which I can't find answered in the documentation.. For many of the records I have, people haven't provided their Middle Initials, and many simply don't have a Suffix. These fields are set to the proper number of blank characters in the record. When I run the report, these column values all get brought up to the top 'n' lines. For example, if only one of two people, the second one in the list has a middle initial, that middle initial will print for the first person, who doesn't have one, and the second person, who should have a middle initial, shows without one. I've tried using "layout=tablular" with no difference.

      Any suggestions for further tries?

        It's probably a bug (and certainly not desirable). I've reported it. The only workaround I can find at the moment is to use "\xa0" (a single non-breaking space) where no data is available. Like so:
        #! /usr/bin/perl -w use strict; use 5.010; use Perl6::Form; my @last = qw(Smith Jones Wright Wong Evans McFee Ho Nuygen Willians H +owlett Jones Peters Milford Tam Lam Soma Egon Wilson); my @first = qw(Jim Jack Wendy Lee Bo Lenord Jan Dana Lindy Kyle Nora J +ane Bill Woo John Mick Lazlo Jenna); my @mid = ("\xa0", "\xa0", 'A', "\xa0", "B", "\xa0", "\xa0", 'A', "\ +xa0", "B", "\xa0", "\xa0", 'A', "\xa0", "B", "\xa0", "\xa0", 'A'); my @suf = ("") x 18; my @nick = qw(Jim Jack Wendy Lee Bo Lenord Jan Dana Lindy Kyle Nora Ja +ne Bill Woo John Mick Lazlo Jenna); my @ID = 1..18; print form { page => { length => 15, number => 1, feed => "\f", footer => "________________________________ +_____________________________________\n", header => { first => "================================ +=====================================\n" . "| xxxxxxxxxxxx +xxxxxxxxxxxxxxxx |\n" . "| xxxxxxxxxx +xxxxxxxxxxxx |\n" . "| + |\n" . "| List +of Players |\n" . "|=============================== +====================================|\n" . "|Last |First + |MI|Suffix|Nickname | ID|\n" . "|_______________________________ +____________________________________|", other => "================================ +=====================================\n" . "| List +of Players |\n" . "|=============================== +====================================|\n" . "|Last |First + |MI|Suffix|Nickname | ID|\n" . "|------------------------------- +------------------------------------|", } } }, "| {]]]]]]]]]]]]]]]]} | {]]]]]]]]]]]]]]]]} |{}| {II} | {]]]]]]} | +{} |\n", \@last, \@first, \@mid,\@suf, \@nick, \ +@ID;