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

Hello Monks.
Right here is the problem
I have a data structure as follows:
%HoH = ( flintstones => { lead => "fred", pal => "barney", }, jetsons => { lead => "george", wife => "jane", "his boy" => "elroy", }, simpsons => { lead => "homer", wife => "marge", kid => "bart", }, );
Now, I wish to generate a TEXT table looking like this:
flintstones jetsons simpsons ------------- --------------- ----------- lead, fred lead , george lead, homer pal , barney wife , jane wife, marge his boy, elroy kid , bart

Ideal place to use formats? You bet. BUT....
I cannot create a format as follows:
format LINE= @<<<<<,@<<<<<< @<<<<<,@<<<<<<<< @<<<<<,@<<<<<<<< $role1,$name1 $role2,$name2 $role3,$name3 .

because, I don't know who many "flintstones, jetsons, simpsons, etc. there will be at the time I create the program.
So, I would like to create a format like this:
format LINE= @<<<<<,@<<<<<< $role ,$name .

Then, when I write the record, I can write the format all on one line over and over while I still have cartoon characters in the HoH.
The effect will be a table in text format.

So there it is.
I know there is the $: operator which gets a brief mention in the perlform docs, and Randall Schwartz mentions some stuff with formats in Learning Perl, but I need something a little more complex.

Thanks monks
Hambo
Open Source - Where everything is QED

Replies are listed 'Best First'.
Re: Using format to creat tabular report
by duff (Parson) on May 12, 2004 at 16:35 UTC
    You can build the format on-the-fly using formline or perhaps a "better" solution would be to use Perl6::Form
Re: Using format to creat tabular report
by fireartist (Chaplain) on May 12, 2004 at 10:54 UTC
    I cannot create a format as follows: ...
    because, I don't know who many ... there will be at the time I create the program.
    Sound like an excellent candidate for creating the format line on the fly and then eval'ing it.