Re: How do I properly use global variables?
- From: rcoops@xxxxxxxxx (Rob Coops)
- Date: Tue, 23 Oct 2007 09:57:58 +0200
You might want to try the following call your script twice with the start
argument, then look at the processes running (just send the output of the
script to /dev/null or something like that for ease of use)
You will see the script running twice, this is because you started the Perl
interpreter twice. If you want to be able to do this you will have to look
into something called signaling. With this you can send your script a signal
to stop, this signal you can then process in anyway you like.
I hope this will help yo a bit, regards,
Rob
On 10/23/07, monk <rsarpi@xxxxxxxxx> wrote:
I'm having problems accessing a variable outside its subroutine.
I've tried several combinations too long to write here. Maybe I just
can't see the forest for the trees. But I'm lost. I need your
wisdom.
I'd like my program below to change $status to zero to exit the loop.
meaning...$> perl test.pl --start
it prints out indefinitely "hello world"
But if $> perl test.pl --stop
it gets out of the loop exiting the program.
#!/usr/bin/perl
use strict;
use warnings;
<snip>
our $status;
sub start{
$status = 1;
while ($status == 1){
print "hello world!\n";
}
print "out of loop. Will exit now";
exit;
}
sub stop {
$status = 0;
}
--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/
- References:
- How do I properly use global variables?
- From: Monk
- How do I properly use global variables?
- Prev by Date: Re: Perl module
- Next by Date: Re: How do I properly use global variables?
- Previous by thread: How do I properly use global variables?
- Next by thread: Re: How do I properly use global variables?
- Index(es):
Relevant Pages
|