On Mon, 14 Nov 2011 23:06:15 -0600
Chris Stinemetz <chrisstinem...@gmail.com> wrote:

> Thank you Shlomi.
> 
> For some reason my final value for the keys is being repeated 24 times so I
> am guessing I have an issue with how I am iterating over the hashes.
> 
> I can't seem to find the correct way to fix it so the value displays once.
> 

In such cases, you should use a debugger:

http://perl-begin.org/topics/debugging/

> Any help is greatly appreciated.
> 
> An example of the output is:

Snipped.

> #!/usr/bin/perl
> use warnings;
> use strict;
> use POSIX;
> use Data::Dumper;
> use diagnostics;
> my $filepath =
> sprintf("/omp/omp-data/logs/OMPROP1/%s.APX",strftime("%y%m%d",localtime));
> my $runTime =
> sprintf("/home/cstine/heh/hehOut/%s.txt",strftime("%Y-%m-%d",localtime));
> my $fileDate = strftime("%y%m%d%H%",localtime);
> open my $FIN, '<', $filepath or die "ERROR opening $filepath: $!";
> open my $out, '>', $runTime or die "ERROR opening $runTime: $!";
> 
> my %CELL;
> my $timestamp;
> my $hour;
> while (my $line = <$FIN>) {
>   if ($line =~ m|\d{1,2}/\d{1,2}/\d{2} ((\d{1,2}):\d{1,2}:\d{1,2})|) {
>   $timestamp = $1;
>   $hour = $2;
>   }
>   if ($line =~ /CELL\s*(\d+)\s*(.*),\s*HEH/) {
>     if ((0 <= $hour)&&($hour <=23)) {
>     $CELL{$hour}{$1}{$2}++;
>     }
>   }
> }
> # header
> print "HOUR\tCELL\tHEH_TYPE\t\tHEH_COUNT\n";
> # body
> foreach my $hour (sort keys %CELL) {
>   foreach my $cellNo (sort keys %{$CELL{$hour}}) {
>     foreach my $hehType (sort keys %{$CELL{$hour}{$cellNo}}) {

Please implement my suggestion of doing:

foreach my $hour (sort keys %CELL) {
        my $hour_rec = $CELL{$hour};
        # Do something with $hour and $hour_rec.


>       print "$hour\t$cellNo\t$hehType";

Do you intend to print it only once?

>       foreach my $hehCount (sort keys %CELL) {
>         print ",$CELL{$hour}{$cellNo}{$hehType}";

The problem here is that you're iterating with $hehCount but accessing the
inner-most hash-reference using $hehType. So it will always print the same
value. I also don't understand why there's another foreach loop to the keys of
%CELL here.

Regards,

        Shlomi Fish

>       }
>       print "\n";
>     }
>   }
> }
> thank you ,
> 
> Chris



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Freecell Solver - http://fc-solve.shlomifish.org/

Chuck Norris can make the statement “This statement is false.” a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to