mikeatrcn has asked for the wisdom of the Perl Monks concerning the following question:
I have 3 issues which I've been wrestling with for over a full day, and cannot find the answers:
At "Error1" below -- Whenever I run the scipt, I get the msg,
But that's what I'm trying to do . . . define the value. And, without MAIN::, I get the error,Can't call method "My" on an undefined value at G:\PERLCODE\NEWSCR~1.C +GI line 23."
global symbol $LogMsg requires explicit package name".
At "Error2" -- I had understood that $^W = 0 would turn off the warnings, but it doesn't. Did I miss something?
Finally, at Error3 -- Without the "my $temp = $MAIN::Log;" statement, I get warnings about "$MAIN::Log only used once", but it's assigned a value at the beginning of MAIN, and then used in the write sub . . .
Thanks in advance for your help!!!
#! perl -w use strict; use diagnostics; use Time::localtime; use Config::IniFiles; MAIN:{ my $DirPath = 'A:\\TempIMS_Work\\Listings\\'; my $Logfile = 'DRS_FileModify.log'; my $StdErrfile = 'DRS_FileModify_StdErr.log'; my $Log = $DirPath.$Logfile; my $StdErr = $DirPath . $StdErrfile; # Just to get around warning of "Only Used Once" my $dummystmt = $Log . $StdErr; #Error1 My $MAIN::LogMsg = "\n\n" . &getDateTime() . "\ - Starting Processing\ +n\n"; # Start the log and StdErrLog &writeLog(); &writeStdErr(); # Ensure the log path exists opendir (Dir, $MAIN::DirPath) or die "\n\nCannot open the path for the processing log: $MAIN +::DirPath -- $!\n"; closedir(Dir); # Loop # Process each DRS file -- Call processDRS_File # EndLoop # If error, FTP the errmsg # if FTP failure, write to logs # if success, write o.k. msg to logs #EOJ } # Subroutines and Functions sub getDateTime {; my $tm = localtime(time); my $ampm = "am"; my $tempHour = undef; if ($tm->hour > 12) {$tempHour = $tm->hour - 12; $ampm = "pm"; } else { $tempHour = $tm->hour; }; return (sprintf("%02d/%02d/%02d %02d:%02d %02s", $tm->mon+1, $tm->mday, substr($tm->year + 1900, 2, 2), $tempHour, $tm->min, $ampm) ); }; sub writeLog() { #Error2 # $^W = 0; open LOGFILE, '>>', "$MAIN::Log" or die "ERROR: Cannot open Log file: $!"; # $^W = 1; #Error3 # my $temp = $MAIN::Log; print LOGFILE $MAIN::LogMsg; close LOGFILE; }; sub writeStdErr() { open STDERRFILE, '>>', "$MAIN::StdErr" or die "ERROR: Cannot open StdErr file: $!"; my $temp = $MAIN::StdErr; print STDERRFILE $MAIN::LogMsg; close STDERRFILE; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Newbie Q re: Undefined Value and "only used once" warnings
by ambrus (Abbot) on May 15, 2004 at 18:31 UTC | |
|
Re: Newbie Q re: Undefined Value and "only used once" warnings
by ambrus (Abbot) on May 15, 2004 at 18:48 UTC | |
by Nkuvu (Priest) on May 15, 2004 at 19:17 UTC | |
|
Re: Newbie Q re: Undefined Value and "only used once" warnings
by Nkuvu (Priest) on May 15, 2004 at 19:11 UTC | |
|
Re: Newbie Q re: Undefined Value and "only used once" warnings
by exussum0 (Vicar) on May 15, 2004 at 17:42 UTC | |
|
Re: Newbie Q re: Undefined Value and "only used once" warnings
by arden (Curate) on May 15, 2004 at 18:33 UTC | |
|
Re: Newbie Q re: Undefined Value and "only used once" warnings
by Errto (Vicar) on May 15, 2004 at 19:31 UTC | |
by mikeatrcn (Acolyte) on May 15, 2004 at 20:28 UTC |