Mike -
I assume you want to know why your Perl script is throwing errors, though
you didn't state this.
Here's my take:
Error:Name "main::Eventype" used only once: possible typo at H:\perl
scripts\wmitimed.pl line 20.
The only place you use $Eventype is in line 20:
if ( $Hash {$Eventype} == Eventlog_Error_Type )
Sorry to quote the error message back at you, but I don't know a clearer
way to say this. Where is this initialized? Do you by any chance mean
if ( $Hash {EventType} == Eventlog_Error_Type )
Name "Win32::Eventlog::GetMessageText" used only once: possible typo at H:
\perl scripts\wmitimed.pl line 3.
Same analysis. Perl is case-sensitive. You want
Win32::EventLog::GetMessageText. As was mentioned in another note, you also
want "use Win32::EventLog;", not "use Win32::Eventlog;".
Can't call method "GetNumber" on an undefined value at H:\perl
scripts\wmitimed.pl line 11.
Again, I don't know how to say it better. Perl is telling you that $Event
is undefined. It's telling you that because it _is_ undefined. Please
excuse the dogmatism, but this question comes up every couple weeks, and
the answer is always the same. Insert
print "'$Event'\n"
before the line that throws the error, if you don't believe me. Unlike the
other "n" people who post over this error because they never bothered to
check whether they instantiated an object, you get it for a rather
interesting reason: $Event is undefined because you never assign it a
value. You never assign it a value because you never say in your code
"$Event = something-or-other".
my $Event - new Win32::EventLog( "System", "" )
does _not_ assign any value to $Event -- it just declares $Event as a "my"
variable, instantiates an event log object and SUBTRACTS the value of the
reference (which will be the value of the numeric part) from the value of
$Event (undef at this point), and throws away both the event log object and
the result of the subtraction. But you don't "die", because the computed
value is not zero.
Okay, why isn't this an error? Two reasons:
* Perl, like many non-ancient languages (C, C++, Java I think) is
expression-based. There is in general nothing wrong with computing a value
and then discarding.
* Perl, like _all_ computer languages, does what you tell it to, not what
you want. It in fact has no way to know what you want, other than what you
tell it.
For a demonstration of _some_ of the points brought out, try
use Win32::EventLog;
my $Event;
my $logger = new Win32::EventLog ("System", "") or
die "Failed to instantiate EventLog object.\n";
print "The logger reference is '$logger', or (as a number) @{[$logger + 0]}\n";
my $result = $Event - $logger;
print "The result is '$result', or (as a number) @{[$result + 0]}\n";
The moral of the above is that displaying a few values will get you a long
way. In general, it's better for everyone, including you, if you attempt to
understand what your Perl script (or any other program) _is_ doing, rather
than asking everyone you can find why it isn't working right.
Tom Wyant
"Mike Singleton" <[EMAIL PROTECTED]>@listserv.ActiveState.com on
08/30/2002 09:13:56 AM
Sent by: [EMAIL PROTECTED]
To: <[EMAIL PROTECTED]>
cc:
Subject: eventlog script help
Error:Name "main::Eventype" used only once: possible typo at H:\perl
scripts\wmitimed.pl line 20.
Name "Win32::Eventlog::GetMessageText" used only once: possible typo at H:
\perl scripts\wmitimed.pl line 3.
Can't call method "GetNumber" on an undefined value at H:\perl
scripts\wmitimed.pl line 11.
Process terminated with exit code 0
====Code =======
use Win32::Eventlog;
# Enable message retrieval
$Win32::Eventlog::GetMessageText = 1;
my $SecPerWeek = 7 * 24 * 60 * 60;
my $Now = time ();
my $WeekAgo = $Now - $SecPerWeek;
my $Num;
my $Event - new Win32::EventLog( "System", "" )
or die " Unable to open eventlog. \n " ;
$~ = "Event_Message";
if( $Event->GetNumber( $Num ) )
{
my $Flag = EventLog_Backwards_Read | Eventlog_Sequential_Read;
my %Hash;
my $fContinue = 1;
do
{
if ( $Event->Read( $Flag, 0, \%Hash ) )
{
if ( $Hash {$Eventype} == Eventlog_Error_Type )
{
local $Message = $Hash{Message} || "No Message";
print "$Hash{Source} on $Hash{Computer} indicated an error ";
print " at " . localtime( $Hash{TimeGenerated} ) . " .\n";
write;
print "\n";
}
}
else
{
$fContinue = 0;
}
} while ($WeekAgo < $Hash{TimeGenerated} && $fContinue );
Win32::EventLog::CloseEventLog( $Event->{handle} );
}
format EVENT_MESSSAGE=
Message:
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Message
~
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Message
~
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Message
~
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Message
~
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Message
~
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Message
~
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.
==== End Code ====
===
Mike Singleton
Network Analyst
(253) 272-1916 x1259
(253) 405-1968 (cellular)
[EMAIL PROTECTED]
DaVita Inc.
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs