Re: Debug Help Please



On Jul 5, 9:54 pm, jwkr...@xxxxxxx (John W. Krahn) wrote:
Andy wrote:

Greets

Hello,

Thanks for your earlier help, but I am still stuck.

I took your advice and I believe I put together the script as you
said.

Except that you apparently haven't yet enabled the warnings and strict
pragmas in your program to help you find your mistakes.



I decided to test with one output file in this case only the failed
log.

I get the creation of the csv but no data .
This is a line from the log I parse
Mon Apr 28 23:55:35 2008 0 X.X.X.X 5 /home3/FTP-protected/IBES/
siteseer/download.tst b _ o r USERNAME ftp 0 * c

#Define LogFiles
my $dateroot = $ARGV[ 0 ]; # Value should be 2-digit month
my $outgoing="outgoing_xferlog.$dateroot.csv"; # This is for all
files sent to users
my $incoming="incoming_xferlog.$dateroot.csv"; #This is log for
uploads
my $loginsinlog="loginsinlog_xferlog.$dateroot.csv"; # This is
wherelog users
my $completedlog="completedlog_xferlog.$dateroot.csv"; # All
Completed Sessions
my $failedlog="failedlog_xferlog.$dateroot.csv"; # This is for
all Failures
my %loginsin;
my %completedlog;
my %failures;
my %incoming;
my %outgoing;

#Time Measured
print "Started Processing Logfiles for $dateroot at " .
(localtimetime) ."\n\n";

'localtimetime' is not a valid Perl function, that should be 'localtime
time' or just 'localtime':

print "Started Processing Logfiles for $dateroot at " . localtime . "\n\n";

If you had enabled the warnings and strict pragmas then perl would have
displayed a message to about that. Please put these two lines at the
top of your program to *help* you find these mistakes:

use warnings;
use strict;



#Open Log File Dir to Read .log file(s)
opendir (DIR, ".") or die "$!";
my @logfiles = grep /xferlog\.$dateroot/, readdir DIR;
close DIR;

#Start Log Processing
foreach my $logfile (@logfiles) {
print "Started Processing: $dateroot at " . (localtime time) ."\n";
open(FH,"./$logfile") or die "$!";
while ( my $line = <FH> ) {
chomp($line);
my @fields = split / /, $line; #This is where we look for the .
extensions

#My Ftp Status Log Values
foreach ($line) { #You mentioned why use this here? Is there a
better way?

foreach loops over a list of items but you only have one scalar in that
list. foreach then aliases $_ to each item in that list in turn but you
never use $_ inside the loop. Therefore the foreach loop is superfluous
and should be removed.

print "HELLO";
my $TIME = [3];

That should be:

my $TIME = fields[3];



my $YEAR = $fields[4];
my $IP = $fields[6];
my $SIZE = $fields[7]; #filesize
my $FILE = $fields[8]; #filename and path
my $DIRECTION = $fields[11]; #Outgoing, Incoming
my $USERNAME = $fields[13];
my $STATUS= $fields[17]; #c = completed
i=incomplete
( my $MASKFILE = $FILE ) =~ tr/0-9/#/;

#Failures This is where we check for
failures
if ($STATUS eq "i" ){$failures {$USERNAME} = $TIME.",".$YEAR.",".
$FILE.",".$IP;}
#completed sessions Last Login
if ($STATUS eq "c" ){$completedlog {$USERNAME} = $TIME.",".
$YEAR.",".
$IP;}

#Completed incoming
if ($DIRECTION eq "i" and $STATUS eq "c" ){$incoming {$USERNAME} =
$TIME.",".$YEAR.",".$FILE.",".$SIZE.",".$IP;}
#Outgoing this is where we log all
outgoing xfers
if ($DIRECTION eq "o" and $STATUS eq "c" ){$outgoing {$USERNAME} =
$TIME.",".$YEAR.",".$FILE.",".$SIZE.",".$IP;}

}
}
close(FH);
}
open(OUTPUT, '>', $failedlog) or die("Could not open log file.");
foreach $key ( sort keys %failures ) {"$key,$failures{$key}\n";}

You have a string in void context inside the loop. If you had enabled
the warnings and strict pragmas then perl would have displayed a message
to that effect. Please put these two lines at the top of your program
to *help* you find these mistakes:

use warnings;
use strict;

close(OUTPUT);

John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Good Morning

Funny how when you talk to different people you get different ways of
looking at it.

One of the Perl guys at my office. told me that I can use
use strict;
use warnings;

but he said , he really doesn't because he wants the script to do what
it needs to do...

I have made corrections as you suggested.
I have included.

use strict;
use warnings;

as well as
my $TIME =$fields[3]

However after that ,
I still get zero output.

Maybe I have this written .....

-Ty

.



Relevant Pages

  • Re: debugger exiting
    ... strict and warnings pragmas. ... I think portraying Perl as a command-line tool limits it to fewer platforms than ... work only as a Unix shell command line. ...
    (perl.beginners)
  • Re: dns querry script.
    ... use warnings; ... use strict; ... C:\Dload> perl dns.pl ...
    (comp.lang.perl.misc)
  • Re: Any way to access global variable in Perl script from one module file?
    ... use strict; ... use warnings; ... a separate process has a completely separate memory space. ... There is probably no reason to create a new perl ...
    (comp.lang.perl.misc)
  • Re: Debug Help Please
    ... In Perl there is the expression TIMTOWTDI which means that you will probably get different opinions on "The Right Way" to do something in Perl. ... use strict; ... That is a specious argument because you can disable specific strictures or warnings in local scope: ... for all Failures ...
    (perl.beginners)
  • Re: Align Text
    ... On Dec 21, 2003, at 10:47 PM, Bill Jastram wrote: ... use strict; ... use warnings; ... These promise Perl you'll play by the good programmer rules, ...
    (perl.beginners)