An experienced pgmmr, I'm totally new to Perl, and appreciate any guidance you might provide.

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,

Can't call method "My" on an undefined value at G:\PERLCODE\NEWSCR~1.C +GI line 23."
But that's what I'm trying to do . . . define the value. And, without MAIN::, I get the error,
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; };

In reply to Newbie Q re: Undefined Value and "only used once" warnings by mikeatrcn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.