All,
Sorry about the HTML being on... Will be more mindful in the
future ;)
I already was running with warnings, which is why I was puzzled. I
changed the declaration to not have the initializing and stripped out
everything that was unrelated to logging this and found my problem: a
misplaced paren!!
Since I copy and pasted the logging line in several places it would fail
anywhere I was logging the particular variable, only when an if
statement failed. Gotta love typos. While I was at it I set it up to
not use globals any more.
-ML
Hello Marc,
Please try to send your messages in plain text format, it's easier for
several members if the list.
It's difficult to detect an error with such a little sample of your
code.
The first thing I can see, is that you are declaring a prototype that
you
don't really need or use. Use your subroutine like this (without
parenthesis
in the sub name):
sub sLogData {
my $string = shift; # collect your first arg
print $string;
if ($flag_log) {
print LOGFILE $string;
}
return 0;
}
Now, you are not specifying the name of your script nor the whole error
message. I don't know how your script is being called, but the error
message
should have at the end information on where the function was called
(script
name and line) and that should give you some clue. Maybe it's being
called
outside scope (inside a different package) or by some other script, but
then
again, you didn't provide too much detail to analize.
Also, always use the followung two lines at the beginning of your
scripts:
use strict;
use warnings;
Those two lines can help you resolve a lot of issues faster.
HTH
Paco Zarabozo
-------------------------------------------------
From: Labelle, Marc S
Sent: Monday, June 30, 2008 1:25 PM
To: [email protected]
Subject: getting "undefined subroutine &main::sLogData" after
callingsuccessfully multiple times in script.
Hello all,
I'm a bit confounded by the error I'm getting.
I've got a small subroutine (listed below) that I call when I need to
post
data to both the console and a logfile.
It is using two globals and one variable passed to it (globals are a
flag to
enable/disable the logfile, and the filehandle).
It's a dead simple subroutine and I don't know what I'm doing wrong.
Basically the script interfaces to some National Instruments hardware
(which
is working fine) and iterates over several options (also working fine).
As
it goes it logs results, data, etc.
Periodically and *not* at the same point in the program each time the
script
will fail with an "undefined subroutine &main::sLogData", this after
it's
successfully called it 20 or 30 times before.
Any thoughts?
Cheers,
-Marc
sub sLogData(@)
{
my $string=$_[0];
print "$string";
if ($flag_log) {print LOGFILE "$string"; }
return(0);
}
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs