On Fri, 27 Jun 2003, Christopher Moss wrote:

> Can anyone help me with this problem? I am trying to produce a report
> using the format function that is in the following format (trivial
> example):
>
> Family Name   Role         Name
> ================================
> flintstones   lead         fred
>               pal          barney
> jetsons       his boy      elroy
>               lead         george
>               wife         jane
> simpsons      kid          bart
>               lead         homer
>               wife         marge
>
> In other words there are repeating groups!
>
> The code I am using, in this case partly taken from the Perldsc as my
> actual data also makes use of a hash of hashes. So far I have been able
> to produce the following:
>
> Family Name   Role         Name
> ================================
> flintstones   lead         fred
> flintstones   pal          barney
> jetsons       his boy      elroy
> jetsons       lead         george
> jetsons       wife         jane
> simpsons      kid          bart
> simpsons      lead         homer
> simpsons      wife         marge
>
> which is not quite right! I have read the docs but I can't see a way to
> define two formats side by side and switch between them. I know the
> other option is to use print/printf but I find the format function very
> useful. Any suggestions would be appreciated.
>
> My code follows:
>
> ...code...
>
> #!perl -w
>
> my %HoH = (
>         flintstones => {
>                 lead      => "fred",
>                 pal       => "barney",
>         },
>         jetsons     => {
>                 lead      => "george",
>                 wife      => "jane",
>                 "his boy" => "elroy",
>         },
>         simpsons    => {
>                 lead      => "homer",
>                 wife      => "marge",
>                 kid       => "bart",
>         },
>  );
>
> open (FORM, ">report2.txt");
>
> my ($rfamily, $rrole, $rname);
>
> foreach $family ( sort keys %HoH ) {
>
>       for $role ( sort keys %{ $HoH{$family} } ) {
>           $rfamily = $family;
>           $rrole = $role;
>           $rname =$HoH{$family}{$role};
>           write FORM;
>       }
>  }
>
> format FORM_TOP =
> Family Name   Role       Name
> ================================
> .
>
> format FORM =
> @<<<<<<<<<<   ^<<<<<<<<    ^<<<<<<<<<<<<
> $rfamily, $rrole, $rname
> .
>
> ....end code....
>

I suggest that, in your loop right after you assign $rfamily that you
put the following line:

                 $rfamily=' ' if $seen{$rfamily}++;

**** [EMAIL PROTECTED] <Carl Jolley>
**** All opinions are my own and not necessarily those of my employer ****

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to