foreach $key (sort keys %ytd ){ ... 
No strict? ... watch out for the Inquisitors! I'll presume that you declared $key earlier. ;)

Seriously, i want to point out that anytime i see variables like $t1, $c1, ,$d1, etc., i try to remove these and use 'containers' instead. Here is my take on the problem:

use strict; my (@stuff,$cust,$total); my %ytd = ( foo => { d1 => 1, d2 => 2, c1 => 3, c2 => 4 }, bar => { d1 => 5, d2 => 6, c1 => 7, c2 => 8 }, baz => { d1 => 9, d2 => 1, c1 => 2, c2 => 3 }, qux => { d1 => 4, d2 => 5, c1 => 2, c2 => 4 }, ); foreach $cust (sort keys %ytd) { my @tot = map { $ytd{$cust}->{"d$_"} - $ytd{$cust}->{"c$_"} } 1..2; $total = do { my $t; $t += $_ for @tot; $t }; @stuff = ( $ytd{$cust}->{d1}, $ytd{$cust}->{c1}, $tot[0], $ytd{$cust}->{d2}, $ytd{$cust}->{c2}, $tot[1], ); write; } format STDOUT = @<<<<<<<<<<<<<<<<<<<< $cust @#####.## @#####.## @#####.## @#####.## @#####.## @#####.## @stuff @#####.## $total .
I think that shoving the number items into an array is more convenient and allows you to use the array in the format instead of the individual scalars.

Without knowing the problem, i can't really comment on your datastructure %ytd, but it might benefit you in terms of maintenance to combine each of the 'dN' and 'cN' pairs into one that contains an array. For example:

my %ytd = ( foo => { d => [1,2], c => [3,4] }, bar => { d => [5,6], c => [7,8] }, baz => { d => [9,1], c => [2,3] }, qux => { d => [4,5], c => [2,4] }, );
Just food for thought. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Question on using format and write by jeffa
in thread Question on using format and write by Popcorn Dave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.