On Jul 7, 4:33 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: > 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
Wow. Thank you . I had actually been playing around and around with it all day . I came up with something that works but I was having a problem with $MY TIME=%fields[3]; It was suggested I used that to retrieve the values Mon Apr 28 23:55:35 Unfortunately fields[3] = TIme Only I was trying to used $TIME for all Of these vars, Leaving $YEAR separately for when we Do yearly scrubs. My end Script before I saw the post is . se strict; use warnings; #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 where log users my $completedlog="completedlog_xferlog.$dateroot.csv"; # All Completed Sessions my $failedlog="failedlog_xferlog.$dateroot.csv"; # This is for all Failures my $fileslog="fileslogog_xferlog.$dateroot.csv"; my %loginsin; my %completed; my %failures; my %incoming; my %outgoing; my %files; #Time Measured print "Started Processing Logfiles for $dateroot at " . (localtime) ."\n\n"; #Open Log File Dir to Read .log file(s) opendir (DIR, ".") or die "$!"; #my @logfiles = grep {/xferlog\.$dateroot/,} readdir DIR; my @logfiles = grep {/$dateroot/,} readdir DIR; close DIR; #Start Log Processing foreach my $logfile (@logfiles) { print "Started Processing: $logfile at " . (localtime) ."\n"; open(FH,"./$logfile") or die "$!"; while ( my $lines = <FH> ) { chomp($lines); my @fields = split / /, $lines; #This is where we look for the . extensions from the file name # next if /^#/; # next if /^(\s)*$/; #My Ftp Status Log Values # my $TIME = ' '; # foreach my $index (1..3) { # $TIME .= $fields[$index] || 'NULL'; # } my $TIME; $TIME = $fields[1] || 'NULL'; $TIME .= $fields[2] || 'NULL'; $TIME .= $fields[3] || 'NULL'; # my $TIME = $fields[1] . ' ' . $fields[2] . ' ' . $fields[3] || 'NULL'; my $YEAR = $fields[4]||'NULL'; my $IP = $fields[6]||'NULL'; my $SIZE = $fields[7]||'NULL'; #filesize my $FILE = $fields[8]||'NULL'; #filename and path my $DIRECTION = $fields[11]||'NULL'; #Outgoing, Incoming my $USERNAME = $fields[13]||'NULL'; my $STATUS= $fields[17]||'NULL'; #c = completed i=incomplete ( my $MASKFILE = $FILE ) =~ tr/0-9/#/; #$cnt = tr/0-9//;# count the digits in $_ #Failures This is where we check for failures if ($STATUS eq "i" ) {$failures {$USERNAME} = $TIME.",". $YEAR.",".$FILE.",".$IP;} #completed sessions if ($STATUS =~ m "c" ) {$completed {$USERNAME} = $TIME.",". $YEAR.",".$IP.",".$FILE.",".$SIZE;} # incoming if ($DIRECTION eq "i" ) {$incoming {$USERNAME} = $TIME.",". $YEAR.",".$FILE.",".$IP;} #Outgoing this is where we log all outgoing xfers if ($DIRECTION eq "o") {$outgoing {$USERNAME} = $TIME.",". $YEAR.",".$FILE.",".$SIZE.",".$IP;} #Masked Options with file extensions if ($DIRECTION eq "i" and $STATUS eq "c" ) {$files {$USERNAME.",".$MASKFILE} = $SIZE.",".$TIME.",".$YEAR.",".$IP;} } } close(FH); #} open(OUTPUT, '>', $incoming) or die("Could not open log file."); for my $key ( sort %incoming) { if ($incoming{$key}) { print OUTPUT "$key,$incoming{$key}\n";}} close(OUTPUT); open(OUTPUT, '>', $outgoing) or die("Could not open log file."); for my $key ( sort %outgoing) { if ($outgoing{$key}) { print OUTPUT "$key,$outgoing{$key}\n";}} close(OUTPUT); open(OUTPUT, '>', $failedlog) or die("Could not open log file."); for my $key ( sort %failures) { if ($failures{$key}) { print OUTPUT "$key,failures{$key}\n";}} close(OUTPUT); open(OUTPUT, '>', $completedlog) or die("Could not open log file."); for my $key ( sort %completed) { if ($completed{$key}) { print OUTPUT "$key,$completed{$key}\n";}} close(OUTPUT); open(OUTPUT, '>', $fileslog) or die("Could not open log file."); for my $key ( sort %files) { if ($files{$key}) { print OUTPUT "$key, $files{$key}\n";}} close(OUTPUT); print "\nFinished Processing Logfiles for $dateroot at " . (localtime ) ."\n\n"; print "This script took ". (time - $^T)/60 ." minutes \n" TY -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/