in reply to Re: Deleting a matching string in an array
in thread Deleting a matching string in an array
Thanks, I did the double slashes since I am using a unc path and did it the way I learned like 9 years ago in a PERL class.
I got the code to remove the unwanted lines but it is not elegant, but I wanted to post it for more comments and advice on how to improve.
I did try a switch statement but could not get it to work so just built the ugly if statement
Thanks again for the help and direction
#!perl #use strict; use Text::CSV_XS; use warnings; use FileHandle; # declarations my($log_file_path)="\\\\dt00mx84\\LogArchive\\www.ksdot.org\\dt00m +h77\\"; my($robot_file)="\\\\dt00mx84\\LogArchive\\Webrobots.txt"; my($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $day +OfWeek, $dayOfYear, $daylightSavings) = localtime(); my$x="ex"; my($extension)=".log"; my($year)=1900+$yearOffset; my($month_new)=1+$month; my $day=$dayOfMonth-1; my @logmessages; # build filename format # this is how log files are named using the yy/mm/dd formatex040101.lo +g if (length($month_new)< 2) { $month_new="0".$month_new }; if (length($dayOfMonth)< 2) { $dayOfMonth="0".$dayOfMonth }; # build input file name and file path to read from my($filename)=$x.substr($year,2).$month_new.$day; my($log_file)=$log_file_path.$filename.$extension; # build output file name and path to write file my($file_name)=substr($year,2).$month_new.$day; my($out_file)=$log_file_path.$file_name.$extension; # Declare the FileHandles and open the input and output files my $fh= new FileHandle; open(LOG, "<$log_file") or die "Could not open file"; @logmessages=<LOG>; close(LOG); my $outfile= new FileHandle; open(OUTFILE, ">$out_file") or die "Could not open file"; foreach $LogLine (@logmessages){ if(($LogLine!~/Slurp/) && ($LogLine!~/Jeeves/)&&($LogLine!~/Go +oglebot/)&&($LogLine!~/FunWebProducts/)&&($LogLine!~/msnbot.htm/)&&($ +LogLine!~/PeoplePal/)&&($LogLine!~/ventura5/)&&($LogLine!~/Speedy/)&& +($LogLine!~/GovDelivery/)&&($LogLine !~ /gif/)&&($LogLine !~ /jpg/)&& +($LogLine !~ /ico/)&&($LogLine !~ /css/)&&($LogLine !~ /js/)&&($LogLi +ne !~ /archive/)&&($LogLine !~ /CazoodleBot/)&&($LogLine !~ /WebTrend +s/)&&($LogLine !~ /ShopWiki/)&&($LogLine !~ /Ultraseek/)&&($LogLine ! +~ /msrbot/)&&($LogLine !~ /Moskow/)&&($LogLine !~ /Gigabot/)) { print OUTFILE $LogLine; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Deleting a matching string in an array
by Cristoforo (Curate) on Oct 30, 2007 at 20:48 UTC | |
by Shamaeso (Initiate) on Oct 30, 2007 at 21:10 UTC | |
by moritz (Cardinal) on Oct 31, 2007 at 06:43 UTC | |
|
Re^3: Deleting a matching string in an array
by Not_a_Number (Prior) on Oct 30, 2007 at 22:42 UTC |