tuakilan has asked for the wisdom of the Perl Monks concerning the following question:
I put the following code to run on a linux box and tried to run it but it gave me some error
use strict; use warnings; use DateTime::Format::Strptime; my $Strp = new DateTime::Format::Strptime(pattern => '%Y-%b-%d %T' +,); my $infile = 'log.txt'; my $outfile = 'report.txt'; my($fh_out, $fh); my %lookup; my $channel = 'TWO'; my $time_delta = 3600; # seconds = 1 hour open($fh_out, '>', $outfile) or die "Could not open outfile: $!"; open($fh, '<', $infile) or die "Could not open logfile: $!"; while (<$fh>) { next unless /$channel/; $_ =~ m/^(.*) UTC.*refs = (\d+)$/; my $dt = $Strp->parse_datetime($1); my $timestamp = $dt ->epoch(); my $refs = $2; if ( defined($lookup{$refs}) && $lookup{$refs} + $time_delta <= $t +imestamp ) { print $fh_out "REFS $refs: occurrences at " . $lookup{$refs} . + "and $timestamp \n"; print "REFS $refs: occurrences at " . $lookup{$refs} . " and $ +timestamp \n"; } $lookup{$refs} = $timestamp; } close $fh_out; #close $fh;
The error seems to stem from here
the $1 and $2 ...my $dt = $Strp->parse_datetime($1); my $timestamp = $dt ->epoch(); my $refs = $2;
I wonder where did i go wrong ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: need help on declaring variables
by Thilosophy (Curate) on Mar 03, 2008 at 06:48 UTC | |
by tuakilan (Acolyte) on Mar 03, 2008 at 07:31 UTC | |
|
Re: need help on declaring variables
by peterdragon (Beadle) on Mar 03, 2008 at 09:05 UTC | |
|
Re: need help on declaring variables
by ysth (Canon) on Mar 03, 2008 at 07:38 UTC | |
|
Re: need help on declaring variables
by almut (Canon) on Mar 03, 2008 at 08:34 UTC | |
|
Re: need help on declaring variables
by hipowls (Curate) on Mar 03, 2008 at 09:35 UTC | |
|
Re: need help on declaring variables
by stiller (Friar) on Mar 03, 2008 at 09:24 UTC |