gorpong@math-cs.kent.edu (Gordon C. Galligher) (09/05/90)
I am attempting to write a function: alarm() in Perl using Perl 3.0 PL28.
I have done the following:
package ALARM;
...comment stuff...
($version, $patchlevel) ..... (Make sure I'm at least perl 3 pl9 for pipe())
sub main'alarm
{
....the body of the function....
}
In my test file (talarm.pl), I do the following:
require "alarm.pl";
print "blah blah blah";
$time = &alarm(10);
The perl execution dies with:
"Undefined subroutine 'alarm' called at ./talarm.pl line 9."
OK, what am I doing wrong? I thought that preceding the alarm subroutine with
the main', I would be putting it into the main's dataspace/stack. This is
obviously not occuring. Perl -d is absolutely no help, even when I 'require'
some functions which do not change packages, it does not know about them
with the 'S' command.
I did not want to post the entire file, because it is over 140 lines, and
that is really out of the scope of my question.
The require does not fail, but the subroutine also does not show up in the
main package. Before you suggest, I tried: $val = &ALARM'alarm(10); and
got the same error, which leads me to believe that something is seriously
wrong, with the way I am doing it, or perl. (Of course, it could not be
ANYTHING that I am doing, could it :-)
Any suggestions would be greatly appreciated. If it would not be too much
trouble, I would appreciate the answers posted, so others can benefit from
this wierdness. Thank you very much.
-- Gordon.
P.S. For the person asking about a timeout for <STDIN>, the sooner I get help
on this problem, the sooner you can have your timeout (hint, hint).
gorpong@kentvax.kent.edu (Gordon C. Galligher) (09/05/90)
Assuming, of course, that I get the first problem solved, what I want to know is how to get some code in the package top to be executed whenever the file is 'require'd or 'do'd (not dude). I have this: # # Does a real alarm() function exist? # eval "alarm(10); alarm(0);"; # Set, then unset (to test) if ( length($@) == 0 ) { $ALARMEXISTS = 1; # Yeah, use alarm() in perl } else # No, so make sure we can { # emulate it in here. ($version, $patchlevel) = $] =~ /(\d+\.\d+).*\nPatch level: (\d+)/; die "Cannot use alarm() in pre-Perl 3.0 PL9 release\n" if $version < 3.0 || ($version >= 3.0 && $patchlevel < 9.0); } This is just in the beginning, and the only thing before it is: package ALARM; and some comments. Is there something else I need to do to get this executed? I also set up some global variables there because I assumed they would be executed when the 'do' happened (or the 'require'). Have I made a bad assumption, or is something else wrong? Perl did pass all of the tests. As I have said many times today, any help you can give me would be greatly appreciated. -- Gordon.