getting "undefined subroutine &main::sLogData" after calling

getting "undefined subroutine &main::sLogData" after calling

am 30.06.2008 20:25:05 von marc.s.labelle

This is a multi-part message in MIME format.

--===============0382402955==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C8DADE.9EBE8466"

This is a multi-part message in MIME format.

------_=_NextPart_001_01C8DADE.9EBE8466
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

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...

=20

Any thoughts?

Cheers,

-Marc

=20

=20

sub sLogData(@)

{

my $string=3D$_[0];

print "$string";

if ($flag_log) {print LOGFILE "$string"; }

return(0);

}

=20

=20


------_=_NextPart_001_01C8DADE.9EBE8466
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">


charset=3Dus-ascii">









style=3D'font-size:10.0pt;
font-family:Arial'>Hello all,



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   I’m
a bit confounded by the error I’m =
getting.



style=3D'font-size:10.0pt;
font-family:Arial'>I’ve got a small subroutine (listed below) that =
I call
when I need to post data to both the console and a =
logfile.



style=3D'font-size:10.0pt;
font-family:Arial'>It is using two globals and one variable passed to it
(globals are a flag to enable/disable the logfile, and the =
filehandle).



style=3D'font-size:10.0pt;
font-family:Arial'>It’s a dead simple subroutine and I don’t =
know
what I’m doing wrong.



style=3D'font-size:10.0pt;
font-family:Arial'>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.



style=3D'font-size:10.0pt;
font-family:Arial'>Periodically and * style=3D'font-weight:bold'>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…



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>Any thoughts?



style=3D'font-size:10.0pt;
font-family:Arial'>Cheers,



style=3D'font-size:10.0pt;
font-family:Arial'>-Marc



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>sub sLogData(@)



style=3D'font-size:10.0pt;
font-family:Arial'>{



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   my
$string=3D$_[0];



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   print
"$string";



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   if
($flag_log) {print LOGFILE "$string"; =
}



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   return(0);



style=3D'font-size:10.0pt;
font-family:Arial'>}



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:
12.0pt'> 









------_=_NextPart_001_01C8DADE.9EBE8466--

--===============0382402955==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0382402955==--

Re: getting "undefined subroutine &main::sLogData" after calling

am 30.06.2008 20:59:50 von geoff

--===============1258513913==
Content-Type: multipart/alternative;
boundary="----=_Part_17132_21669917.1214852390340"

------=_Part_17132_21669917.1214852390340
Content-Type: text/plain; charset=WINDOWS-1252
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

It doesn't look to me like there can be much wrong with the sub.

I tend to use the following sort of construct instead of the IF test,
however:

$flag_log and print LOGFILE "$string";

I would guess that the problem has more to do with the environment that the
sub is being called from than the sub itself.

--Geoff

On Mon, Jun 30, 2008 at 2:25 PM, Labelle, Marc S
wrote:

> 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 pos=
t
> 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 aft=
er
> it's successfully called it 20 or 30 times before=85
>
>
>
> Any thoughts?
>
> Cheers,
>
> -Marc
>
>
>
>
>
> sub sLogData(@)
>
> {
>
> my $string=3D$_[0];
>
> print "$string";
>
> if ($flag_log) {print LOGFILE "$string"; }
>
> return(0);
>
> }
>
>
>
>
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>



--=20
--Geoff
Cell: (313)506-7295
Sterling Heights CERT
'04 Grand Cherokee | '05 Town & Country
http://www.moparmailinglist.com

------=_Part_17132_21669917.1214852390340
Content-Type: text/html; charset=WINDOWS-1252
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

It doesn't look to me like there can be much wrong with the sub.
>I tend to use the following sort of construct instead of the IF test, howe=
ver:

$flag_log and print LOGFILE "$string";

I would=
guess that the problem has more to do with the environment that the sub is=
being called from than the sub itself.


--Geoff

On Mon, Jun 30, 2008 at 2:25 =
PM, Labelle, Marc S <marc.s.=
labelle@intel.com
> wrote:
=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; p=
adding-left: 1ex;">













ily: Arial;">Hello all,



ily: Arial;">          &n=
bsp; I'm
a bit confounded by the error I'm getting.



ily: Arial;">I've got a small subroutine (listed below) that I call
when I need to post data to both the console and a logfile.
p>

ily: Arial;">It is using two globals and one variable passed to it
(globals are a flag to enable/disable the logfile, and the filehandle). an>



ily: Arial;">It's a dead simple subroutine and I don't know
what I'm doing wrong.



ily: Arial;">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.
p>

ily: Arial;">Periodically and *not pan>*
at the same point in the program each time the script will fail with an "un=
defined
subroutine &main::sLogData", this after it's successfully
called it 20 or 30 times before=85



ily: Arial;"> 



ily: Arial;">Any thoughts?



ily: Arial;">Cheers,



ily: Arial;">-Marc



ily: Arial;"> 



ily: Arial;"> 



ily: Arial;">sub sLogData(@)



ily: Arial;">{



ily: Arial;">          &n=
bsp; my
$string=3D$_[0];



ily: Arial;">          &n=
bsp; print
"$string";



ily: Arial;">          &n=
bsp; if
($flag_log) {print LOGFILE "$string"; }



ily: Arial;">          &n=
bsp; return(0);



ily: Arial;">}



ily: Arial;"> 



;"> 









_______________________________________________

ActivePerl mailing list

ActivePerl@listserv.=
ActiveState.com


To unsubscribe: target=3D"_blank">http://listserv.ActiveState.com/mailman/my subs
lockquote>



--
--Geoff
Cell: (313)506-=
7295

Sterling Heights CERT
'04 Grand Cherokee | '05 Town & Countr=
y
http://www.moparmailinglis=
t.com


------=_Part_17132_21669917.1214852390340--

--===============1258513913==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1258513913==--

RE: getting "undefined subroutine &main::sLogData" after

am 30.06.2008 21:06:36 von Wayne Simmons

>Periodically and *not* at the same point in the program each time the
script will fail with an =93undefined subroutine &main::sLogData=94, this a=
fter
it=92s successfully >called it 20 or 30 times before=85

Undefined errors could come from scoping issues or if you undef the routine.
Do you have a variable by the same name? We can only guess without the part
that is actually failing: the =93interfaces to some National Instruments
hardware (which is working fine) and iterates over several options (also
working fine)=94 I what we need to see. =



-Wayne
--
Software Engineer
InterSystems USA, Inc.
303-858-1000
=A0 =

________________________________________
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of Labelle,
Marc S
Sent: Monday, June 30, 2008 12:25 PM
To: ActivePerl@listserv.ActiveState.com
Subject: getting "undefined subroutine &main::sLogData" after
callingsuccessfully multiple times in script.

Hello all,
          =A0 I=92m a bit confounded by the error I=92m=
getting.
I=92ve 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=92s a dead simple subroutine and I don=92t know what I=92m doing wrong.
Basically the script interfaces to some National Instruments hardware (which
is working fine) and iterates over several options (also working fine). =A0=
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 =93undefined subroutine &main::sLogData=94, this after it=
=92s
successfully called it 20 or 30 times before=85

Any thoughts?
Cheers,
-Marc


sub sLogData(@)
{
          =A0 my $string=3D$_[0];
          =A0 print "$string";
          =A0 if ($flag_log) {print LOGFILE "$string"; }
          =A0 return(0);
}




_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: getting "undefined subroutine &main::sLogData" after calling

am 30.06.2008 21:09:21 von Michael Ellery

Labelle, Marc S wrote:

>
> 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...
>

>
>
>
> sub sLogData(@)
>


I notice you are using protypes here. Is it possible that coercion is
mucking things up in some calling cases? I have zero experience with
prototypes in perl, thus I'm only speculating. Have you tried removing
the prototype?

-Mike

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: getting "undefined subroutine &main::sLogData" after calling

am 30.06.2008 21:23:51 von basil.daoust

This is a multi-part message in MIME format.
--===============1167716746==
Content-Type: multipart/alternative;
boundary="------------060409050508020305060602"

This is a multi-part message in MIME format.
--------------060409050508020305060602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Labelle, Marc S wrote:
>
> 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);
>
> }
>
>
>
> ---------
Looks like one of those working fine routines is calling the log
function with a null string breaking the prototyping.
Here is my tests and results.

#!/perl
use warnings;
use strict;
my $flag_log;

sub sLogData(@)
{
my $string=$_[0];
print "$string";
if ($flag_log) {print LOGFILE "$string"; }
return(0);
}

open(LOGFILE,">LOGFILE.TXT");
$flag_log=1;
sLogData("Test string 1\n");
sLogData("");
sLogData("Test string 2\n");
SLogData();
sLogData("Test string 3\n");


Results:
----------------
Test string 1
Test string 2
Undefined subroutine &main::SLogData called at play.pl line 19.

--------------060409050508020305060602
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit







Labelle, Marc S wrote:
cite="mid:4D97B70CF7F72144881F66DFF4BD7A12042F127A@fmsmsx413 .amr.corp.intel.com"
type="cite">




style="font-size: 10pt; font-family: Arial;">Hello all,


style="font-size: 10pt; font-family: Arial;">            I’m
a bit confounded by the error I’m getting.


style="font-size: 10pt; font-family: Arial;">I’ve got a small
subroutine (listed below) that I call
when I need to post data to both the console and a logfile.


style="font-size: 10pt; font-family: Arial;">It is using two globals
and one variable passed to it
(globals are a flag to enable/disable the logfile, and the filehandle).


style="font-size: 10pt; font-family: Arial;">It’s a dead simple
subroutine and I don’t know
what I’m doing wrong.


style="font-size: 10pt; font-family: Arial;">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.


style="font-size: 10pt; font-family: Arial;">Periodically and * style="font-weight: bold;">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…


style="font-size: 10pt; font-family: Arial;"> 


style="font-size: 10pt; font-family: Arial;">Any thoughts?


style="font-size: 10pt; font-family: Arial;">Cheers,


style="font-size: 10pt; font-family: Arial;">-Marc


style="font-size: 10pt; font-family: Arial;"> 


style="font-size: 10pt; font-family: Arial;"> 


style="font-size: 10pt; font-family: Arial;">sub sLogData(@)


style="font-size: 10pt; font-family: Arial;">{


style="font-size: 10pt; font-family: Arial;">            my
$string=$_[0];


style="font-size: 10pt; font-family: Arial;">            print
"$string";


style="font-size: 10pt; font-family: Arial;">            if
($flag_log) {print LOGFILE "$string"; }


style="font-size: 10pt; font-family: Arial;">            return(0);


style="font-size: 10pt; font-family: Arial;">}


style="font-size: 10pt; font-family: Arial;"> 



---------


Looks like one of those working fine routines is calling the log
function with a null string breaking the prototyping.

Here is my tests and results.



#!/perl

use warnings;

use strict;

my $flag_log;



sub sLogData(@)

{

   my $string=$_[0];

   print "$string";

   if ($flag_log) {print LOGFILE "$string"; }

   return(0);

}



open(LOGFILE,">LOGFILE.TXT");

$flag_log=1;

sLogData("Test string 1\n");

sLogData("");

sLogData("Test string 2\n");

SLogData();

sLogData("Test string 3\n");





Results:

----------------

Test string 1

Test string 2

Undefined subroutine &main::SLogData called at play.pl line 19.




--------------060409050508020305060602--

--===============1167716746==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1167716746==--

Re: getting "undefined subroutine &main::sLogData" after

am 01.07.2008 03:21:25 von fzarabozo

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: ActivePerl@listserv.ActiveState.com
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
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: getting "undefined subroutine &main::sLogData" after calling

am 01.07.2008 11:26:13 von Ingo Schwarze

Hi Basil,

Basil A. Daoust wrote on Mon, Jun 30, 2008 at 02:23:51PM -0500:

[...]
> sub sLogData(@)
[...]
> SLogData();
[...]
> Undefined subroutine &main::SLogData called at play.pl line 19.

Indeed, but that's a typo unrelated to the OP's question.
Correcting that typo, you get:

Test string 1
Test string 2
Use of uninitialized value in string at ./sLogData.pl line 9.
Use of uninitialized value in string at ./sLogData.pl line 10.
Test string 3

Calling a (@)-prototyped funtion without arguments is OK, arrays can
be empty, and besides, the prototype check happens at compile time,
not at run time, which is the whole point of prototyping.
Finally, it produces a different Perl error message on failure.
Changing (@) to ($), you get:

Not enough arguments for main::sLogData at ./sLogData.pl line 19, near "()"
Execution of ./sLogData.pl aborted due to compilation errors.

Yours,
Ingo

--
Bad advice alert above... ;-)
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: getting "undefined subroutine &main::sLogData" after

am 01.07.2008 18:03:09 von marc.s.labelle

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: ActivePerl@listserv.ActiveState.com
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
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs