in reply to Re^2: Has McAfee UpdateLog.txt been updated recently
in thread Has McAfee UpdateLog.txt been updated recently
My (untested) reworked version of your code is:
#!/usr/bin/perl use strict; use warnings; print "Backing up old timesNT.txt... \n"; rename ("timesNT.txt", "bac/timesNT.bac") || die "Cannot rename timesN +T.txt: $!"; open (NODELIST, "nodelistNT.txt") or die "I could not get at nodelist. +txt as input"; open (TIMES, ">>timesNT.txt") or die "I could not open times.txt as ou +tput"; my $time = localtime(time()); print TIMES "$time.--------------------------------------------------- +------------\n\n"; while (<NODELIST>) { chomp; my $name = $_; print "$name \n"; my $ntfile = "\"\\\\$name\\c\$\\WINNT\\Profiles\\All Users\\Applic +ation Data\\Network Associates\\VirusScan\\UpdateLog.txt\""; my $isfile = `dir /B $ntfile`; if ($isfile ne "") { my $fname = "//$name/c\$/WINNT/Profiles/All Users/Application +Data/Network Associates/VirusScan/UpdateLog.txt"; print "${name}'s system is NT!\n"; STUFF ($name, $fname); } else { my $fname = "//$name/c\$/Documents and Settings/All Users/Appl +ication Data/Network Associates/VirusScan/UpdateLog.txt"; print "${name}'s system is XP!\n"; STUFF ($name, $fname); } } close NODELIST; close TIMES; sub STUFF { my ($name, $fname) = @_; my $modded = -M $fname; return if $modded < 2; print TIMES "Server Name: $name\n"; print TIMES "$modded\n\n"; }
Note that "Eschew globals" and "Pass parameters" are related.
I was going to add something about removing cruft - removing the redundant use is good. I notice however that you used lowercase for the module name. You absolutly must use the correct case! Especially on Windows, which is case insensitive for file name, nasty and confusing things happen if the module case is not correct.
If you want to generate consistent formatting you might want to take a look at Perl::Tidy.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Has McAfee UpdateLog.txt been updated recently
by calin (Deacon) on Dec 22, 2006 at 11:27 UTC |