Fellow monks,

For the first time in my Perl programming, I've had to use formats. Up until now I haven't had a need to use them.

I've gone through the docs, and the Perl Black Book, but I'm not getting output from my data. Well I sort of am, but it's all 0.00 and blanks for the name - not exactly what I want.

My format code is:

format STDOUT = @<<<<<<<<<<<<<<<<<<<< $cust @#####.## @#####.## @#####.## @#####.## @#####.## @#####. +## $d1, $c1, $t1, $d2, $c2,$t2 @#####.## $total .

and the code producing the data is:

foreach $key (sort keys %ytd ){ my ($cust, $d1, $d2, $c1, $c2); my $t1 = $ytd{$key}->{d1}-$ytd{$key}->{c1}; my $t2 = $ytd{$key}->{d2}-$ytd{$key}->{c2}; $total = $t2-$t1; $cust = $key; $d1= $ytd{$key}->{d1}; $d2= $ytd{$key}->{d2}; $c1= $ytd{$key}->{c1}; $c2= $ytd{$key}->{c2}; write; }

but I've done something wrong as I'm not getting values out. I've confirmed that I do have vaild data using print statements, so I believe I've narrowed it down to a problem with my format statement.

My other question is if I can just use the foreach function to pass the variables directly to the write function or do I need to assign each one as I tried to do.

Thanks in advance for any help with this!

There is no emoticon for what I'm feeling now.


In reply to 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.