Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:
Although Jeffa was kind enough to try and help me with my problem, I'm still stuck.
I've got the following code:
#!/usr/bin/perl -w use strict 'vars'; my %list; my ($key, $value, $cust, $total); format STDOUT_TOP = +-----------------------------------------------------------------+ | Monthly Recap | |----------------------------+----------+-----------+-------------+ |Account | Prior | Current | Difference | |----------------------------+----------+-----------+-------------+ . format STDOUT = |@<<<<<<<<<<<<<<<<<<<<<<<<<<<|@#####.## | @#####.## | @#####.## | $cust,$list{$cust}->{prior}, $list{$cust}->{new}, $total |----------------------------+----------+-----------+-------------+ . &readfile('sfoct01.txt', 'prior'); # &readfile('sfnov01.txt', 'new'); &printdata; sub readfile{ my ($file, $money) = @_; my ($line, $amount); die unless open FH, $file; while ($line = <FH>){ chomp($line); ($cust, $amount) = split('",',($line)); $cust =~ s/"//g; if (exists $list{$cust}){ $list{$cust}->{$money} += $amount; } else{ $list{$cust}->{$money} = $amount; } $list{$cust}->{new} = 10; } close FH; } sub printdata{ foreach $cust (sort keys %list){ $total = $list{$cust}->{new} - $list{$cust}->{pr +ior}; write; } }
Which is all very well and simple and good, but it isn't working!
Well it is working from the standpoint that my data structure is being built correctly. However my data output is the last item in the hash, for every item in the hash. The only data that is correct is the calculated value $total.
What I can't seem to get a handle on is if it is possible to use the HoH variables in the format statement or do I have to use temporary variables?
There is no emoticon for what I'm feeling now.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using HoH data in formats
by jarich (Curate) on Dec 20, 2002 at 01:36 UTC | |
|
Re: Using HoH data in formats
by BrowserUk (Patriarch) on Dec 20, 2002 at 01:46 UTC | |
|
(jeffa) Re: Using HoH data in formats
by jeffa (Bishop) on Dec 20, 2002 at 04:34 UTC | |
|
Re: Using HoH data in formats
by ibanix (Hermit) on Dec 20, 2002 at 01:31 UTC | |
by Popcorn Dave (Abbot) on Dec 20, 2002 at 04:53 UTC |