Re: Until loop

[email protected] (Steve Johnson) Mon, 01 Apr 2002 21:51:05 +0100
Newsgroups perl.riscos
Message-ID <[email protected]>
In message <[email protected]>
          "Richard Torrens (RiscOS)" <[email protected]> wrote:

> In article <[email protected]>,
>    Nicholas Clark <[email protected]> wrote:
> > On Mon, Apr 01, 2002 at 09:47:49AM +0100, Richard Torrens (RiscOS) wrote:
> > > an anyone tell me why the following gets stuck?
> > > 
> > > until ($ENV{'BlackHole$BinDir'} eq "") {
> > >   system ('Unset BlackHole$BinDir');
> > > }
> > > 
> > > It gets stuck in a loop as if the test is only tested once.
> 
[snip]

I thought I'd just add my "two cents" worth (as I've written a few fairly
complex Perl scripts running on Unix!)...

Basically I always try to think in "Unix" mode for this sort of thing,
particularly as Perl was no doubt written with such "basic assumptions". 
Your original code just wouldn't work on Unix because the "system" command
executes in a child process and therefore has it's own environment (and
doesn't affect the parent's). I would therefore use another method for my
"OS code" to communicate back to Perl. eg:

# cut down example - I put in more info in all messages in my "real" code
my $result = "";
until ($result eq "Done") {
  open INP, "{os-code} |" or die "Pipe failed";
  chomp ($result = <INP>);
  close INP;
}

I know we don't have such process separation in RISC OS (for OS Envs
anyway), so it *shouldn't* be necessary, but you never know - one day the
underlying OS might be changed to Unix !  (... nahh! silly idea!  8-)
-- 
Steve Johnson  (mailto:[email protected])
Falls don't kill people. It's the deceleration trauma.