On 10/28/11 Fri  Oct 28, 2011  2:15 PM, "Chris Stinemetz"
<chrisstinem...@gmail.com> scribbled:

> On Wed, Oct 19, 2011 at 1:10 AM, Leo Susanto <leosusa...@gmail.com> wrote:
> 
>> use strict;
>> my %CELL;
>> my %CELL_TYPE_COUNT;
>> my $timestamp;
>> my $hour;
>> while (my $line = <DATA>) {
>>        if ($line =~ m|\d{1,2}/\d{1,2}/\d{2} ((\d{1,2}):\d{1,2}:\d{1,2})|) {
>> #10/17/11 18:25:20 #578030
>>                $timestamp = $1;
>>                $hour = $2;
>>        }
>> 
>>        if ($line =~ /CELL\s+(\d+)\s+(.+?),.+?HEH/) { # take CELL number
>> into
>> $1 and the information after the number (and before the first comma)
>> into $2
>>                if ((17 <= $hour)&&($hour <=21)) {
>>                        $CELL{$hour}{$1}{$2}++;
>>                        $CELL_TYPE_COUNT{$2}++;
>>                }
>>        }
>> }
>> 
>> 
>> 
> 
> Would someone help me understand what this block of code is doing after the
> if condition? Is it utilizing references and counting the occurences of the
> keys?
> I am having some trouble digesting it.

The best way to figure what it is doing is to print out the values of $hour,
$1, and $2, $CELL{$hour}{$1}{$2}, and $CELL_TYPE_COUNT{$2} before and after
the if statement block.

You should be able to combine those two regular expression being applied to
$line, but I would need to see typical data lines to make sure and how to do
that.

It looks like it is counting cells and cell types, judging from the names of
the variables and the comments.



-- 
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