How do I properly use global variables?
- From: rsarpi@xxxxxxxxx (Monk)
- Date: Tue, 23 Oct 2007 02:18:02 -0000
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;
}
.
- Follow-Ups:
- Re: How do I properly use global variables?
- From: Jeff Pang
- Re: How do I properly use global variables?
- From: Rob Coops
- Re: How do I properly use global variables?
- Prev by Date: Re: Absolute noobie question regarding opening files on Windows platform
- Next by Date: pattren maching and mail sending please help !
- Previous by thread: Absolute noobie question regarding opening files on Windows platform
- Next by thread: Re: How do I properly use global variables?
- Index(es):
Relevant Pages
|