rmck <[EMAIL PROTECTED]> wrote: Please stop top posting.
: I had to add a "print $sum !=" to inside and outside the : while loop. Im not sure why it is working this way?? Also : Im getting an error "Use of uninitialized value in string : ne at ./clean1.pl line 28, <LOG> line 1." ?? Break it down to a smaller test case. use strict; use warnings; my $prev_date; if ( $prev_date ne 'foo' ) { ## LINE 28 ## print 'foo'; } Since prev_date does not have value, it cannot be compared without raising a warning. On the second pass $prev_date has a value. : #!/usr/bin/perl : use Socket; : use strict; : use POSIX 'strftime'; : use warnings; : my $line = $ARGV[0]; Better named $file or $log_file. : my $time = strftime "%y%m%d%H", localtime; Not used in this script. : my $sum = 0; : my $prev_date; Undefined on first pass of the while loop. : # open the file : open(LOG,"$line") or die "Unable to open LOG:$!\n"; Don't quote $line. Don't place a newline after $!. It suppresses line number info. open LOG, $line or die "Unable to open LOG: $!"; Or: open LOG, "<$line" or die "Unable to open LOG: $!"; : print "Date_Time, SRCIP, DSTIP, TOTALBYTES \n"; Ahem... print "Date_Time, SRCIP, DSTIP, TOTALBYTES\n"; : # read it in one record at a time : #while (<LOG>) { : while ($line = <LOG>) { while ( my $line = <LOG> ) { : next if $line =~ /^\D/; chomp $line; : my ($logdate,$srcip,$dstip,$totalbytes) = split(/\t/,$line); : my ($date,$time)= split(/\s/,$logdate); Why do $current_date amd $prev_date use the underscore to separate words and the other variables use abbreviations and no seperation? my( $log_date, $source_ip, $destination_ip, $total_bytes, ) = split /\t/, $line; : my @hour = split(/:/,$time); Better written as a scalar. my $hour = ( split /:/, $time )[0]; : my $current_date = $date; : if ($hour[0] >= 6 and $hour[0] < 22){ : if ($prev_date ne $current_date) { ##LINE 28## $prev_date is not defined on first pass. : #print "Total: $sum\n"; # display before clearing, : Prints a Total: 0 on first line : if ($sum != 0) { : print "Total: $sum\n"; : } : $sum = 0; : } : $sum += $totalbytes; : $prev_date = $current_date; : : print "$logdate,$srcip,$dstip,$totalbytes"; You probably want a newline at the end. print "$logdate,$srcip,$dstip,$totalbytes\n"; : } : : # End Of While: : } You don't need this if you line up your indentation. Every time you start a new code block indent your code. When the block ends, outdent it. while ( <LOG> ) { next if /^\D/; chomp; my( $log_date, $source_ip, $destination_ip, $total_bytes ) = split /\t/; my( $current_date, $time ) = split ' ', $log_date; my $hour = ( split /:/, $time )[0]; if ( $hour > 5 and $hour < 22 ) { if ( $prev_date ne $current_date ) { print "Total: $sum\n" if $sum; $prev_date = $current_date; $sum = 0; } $sum += $total_bytes; print "$log_date,$source_ip,$destination_ip,$total_bytes"; } } HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>