#!/local/scripts/perl # this is designed to strip the pics out of the weblogs # set some values $imgdir="pics"; %months=( "Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12" ); # if no args then usage #print join (", ", @ARGV); $args = $#ARGV+1; print "\nThere are $args files\n"; if ($#ARGV lt 0) { &usage; exit; }; # else step through args foreach $file (@ARGV) { # if the file exists if (-e $file) { # open it open (FYLE, $file) ; # read it in @all_lines = ; # close it close (FYLE); } else { print "File $file doesn't exist\n"; next; }; # end if..else # reset the date & array $logdate = ""; $#new = -1; $count=0; # for each line in the filearray foreach $line (@all_lines) { # keep it if it's a comment if ($line =~ /^\#/) { push(@new, $line); next; } # if it has a date, parse & store it if ($logdate eq "") { if ($line =~ /\[(\d{2})\/(\w{3})\w*\/(\d{4}):/) { $day = $1; $month = $2; $year = $3; $monnum = $months{"$month"}; $logdate= $monnum.$day.$year; }; # end if line }; # end if logdate # # if it has $imgdir in it, don't add it if ($line =~ /\/$imgdir\//) { next; } else { push(@new, $line); $count+=1; }; # end if..else }; # end foreach line # write the new file open (NEWFILE, ">wl$logdate") or warn("$0 can't create wl$logdate "); print NEWFILE "# There were $count non-\"$imgdir\" hits for $month $day, $year.\n# \n"; print NEWFILE @new; close NEWFILE; # unlink the parsed file unlink $file; }; # end foreach argv $, = "\n"; print "Files processed:\n", @ARGV, "\n"; ##################### sub usage { print "you gave no arguments. Try again.\n"; }; 1