Andy wrote:

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

Yes, that is how the world works. In Perl there is the expression TIMTOWTDI (There Is More Than One Way To Do It) which means that you will probably get different opinions on "The Right Way" to do something in Perl.


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

That is a specious argument because you can disable specific strictures or warnings in local scope:

$ perl -le'
use strict;
{   no strict "vars";
    $x = 8;  # line 4
}
$y = 9;      # line 6
'
Global symbol "$y" requires explicit package name at -e line 6.
Execution of -e aborted due to compilation errors.

$ perl -le'
use warnings;
my $x;
{   no warnings "uninitialized";
    print "$x";  # line 5
}
print "$x";      # line 7
'

Use of uninitialized value in string at -e line 7.


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

OK, based on your original code and example data line:

#!/usr/bin/perl
use warnings;
use strict;

# Store the program name without the path, if any
( my $program = $0 ) =~ s!.*/!!s;

# User should supply a valid month number
my ( $dateroot ) = map sprintf( '%02d', $_ ), $ARGV[ 0 ] =~ /\A([1-9]|1[0-2])\z/;
defined $dateroot or die "usage: $program [month number]\n";

# Define LogFiles
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 where log users my $completedlog = "completedlog_xferlog.$dateroot.csv"; # All Completed Sessions my $failedlog = "failedlog_xferlog.$dateroot.csv"; # This is for all Failures

#Time Measured
print "Started Processing Logfiles for $dateroot at ", scalar localtime, "\n\n";
#Open Log File Dir to Read .log file(s)
my @logfiles = do {
    opendir my $DIR, '.' or die "Cannot open '.' $!";
    grep /xferlog\.$dateroot/, readdir $DIR;
    };

#Start Log Processing
my %failures;
my %completedlog;
my %incoming;
my %outgoing;
for my $logfile ( @logfiles ) {
    print "Started Processing: $dateroot at ", scalar localtime, "\n";
    open my $FH, '<', $logfile or die "Cannot open '$logfile' $!";
    while ( <$FH> ) {
        #My Ftp Status Log Values
next unless my ( $time, $year, $IP, $size, $name, $direction, $user, $status ) = /
                    \S+\s+\S+\s+\d+\s+
                    (\d\d:\d\d:\d\d)   # field  3 - time
                    \s+
                    (\d{4})            # field  4 - year
                    \s+\S+\s+
                    ([\d.]+)           # field  6 - IP address
                    \s+
                    (\d+)              # field  7 - file size
                    \s+
                    (\S+)              # field  8 - file name and path
                    \s+\S+\s+\S+\s+
                    ([io])             # field 11 - Outgoing or Incoming
                    \s+\S+\s+
                    (\S+)              # field 13 - user name
                    \s+\S+\s+\S+\s+\S+\s+
([ci]) # field 17 - c = completed i = incomplete
                    /x;

        ( my $maskfile = $name ) =~ tr/0-9/#/;

        #Failures    This is where we check for failures
        if ( $status eq 'i' ) {
            $failures{ $user } = "$time,$year,$name,$IP";
            next;
            }

        #completed sessions    Last Login
        $completedlog{ $user } = "$time,$year,$IP";

        #Completed incoming
        if ( $direction eq 'i' ) {
            $incoming{ $user } = "$time,$year,$name,$size,$IP";

#Masked Options with file extensions will be added for later use $completedlog{ "$user,$maskfile" } = "$name,$time,$year,$IP,$status";
            }
        #Outgoing      this is where we log all outgoing xfers
        elsif ( $direction eq 'o' ) {
            $outgoing{ $user } = "$time,$year,$name,$size,$IP";
            }
        }
    }

open my $OUT1, '>', $incoming     or die "Could not open '$incoming' $!";
open my $OUT2, '>', $failedlog    or die "Could not open '$failedlog' $!";
open my $OUT3, '>', $completedlog or die "Could not open '$completedlog' $!";
for my $key ( sort keys %failures ) {
    print $OUT1 "$key,$failures{$key}\n";
    print $OUT2 "$key,$failures{$key}\n";
    print $OUT3 "$key,$failures{$key}\n";
    }
close $OUT3;
close $OUT2;
close $OUT1;

print "\nFinished Processing Logfiles for $dateroot at ", scalar localtime, "\n\n";
print "This script took ", ( time() - $^T ) / 60, " minutes\n"

__END__



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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to