in reply to Re: Has McAfee UpdateLog.txt been updated recently
in thread Has McAfee UpdateLog.txt been updated recently

"Put all your use statements at the top of the file - they are global anyway"
I deleted the use file::find as I am not usig it in the script it was left over from a previous attempt at somehting I did nto quite understand. :)

"Eschew global variable - declare fname, $name ... where they are first used"
When I do this I get an error "Use of uninitialized value in -M at G:\RemoteRegChecks\McAfee Update Check\Nonam e1NT.pl line 45, <NODELIST> line 14.
Use of uninitialized value in numeric ge (>=) at G:\RemoteRegChecks\McAfee Updat e Check\Noname1NT.pl line 49, <NODELIST> line 14.
But when I put the declaration at the top of the script I do not have the problem.

"use consistent indentation that reflects block nesting"
I am working my best at this for teh life of me I can never please anyone on this, need to take some classes LOL

"Pass parameters to subs rather than relying on global variables - it's easier to see where things are used and where they come from."
Would you be able ot elaborate on thsi for me? not quite sure what you mean, in the meantime I will be doing some internet searching for tutorials that mention it. :D

"multiple ! are a sign of a sick mind ;)"
How did you know!!!!????? LOL This is mainly there during my testing phase, it prints that out to the command prompt so I could see that part is working :) I will take it out so I do not look as sick anymore (but that does nto mean I am any less sick in the head :) )

Thank you so far for what you have said, it has me looking at the script more on the formatting side of things to try and get it to look better as well as looking for what is going on with the passing parameters thing (I am wondering if that is what is causing me to get teh errors when I try to declare $fname and $name on first use).

  • Comment on Re^2: Has McAfee UpdateLog.txt been updated recently

Replies are listed 'Best First'.
Re^3: Has McAfee UpdateLog.txt been updated recently
by GrandFather (Saint) on Dec 22, 2006 at 01:29 UTC

    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.


    DWIM is Perl's answer to Gödel

      nit:

      print TIMES "$time." . '-' x 63 . "\n\n";'

      And no, I didn't count the dashes one by one.

      $ perl -le 'print tr/-// for "$time.---------------------------------- +-----------------------------\n\n"'

      In addition, try to avoid the backslash hell downstream in the code.