On Sun, Jul 30, 2000 at 02:38:25PM +0100, Roger Horne wrote:
> On Sat 29 Jul, Vincent Lefevre wrote:
> > Consider the following Perl script:
> > 
> > $_ = $ENV{'Alias$blah'};
> > tr/\000/./;
> > print "$_\n";
> > 
> > I define the following alias:
> > 
> > *Alias blah a|@b
> > 
> > and
> > 
> > *Show Alias$blah
> > 
> > says:
> > 
> > Alias$blah : a|@b
> > 
> > But if I execute the script, only the "a" is printed.
> > 
> > I have Perl 5.005_03, release 1.13.
> > 
> 
> Can a single | be part of an environment variable so far as Perl is
> concerned? May it not be treated as an alternative? I note that *set BLAH
> (rather than *alias BLAH) a||@b produces a|@b when the script is run and
> *set BLAH a|||@b produces a| (*set BLAH a||||@b produces a||@b ...)
> 
> Just out of interest why do you want a | in an environmment variable?


I think you've misunderstood. Environment variables here are being defined
and displayed by RISC OS in GSTRANS notation. The |@ is a literal \0 byte.
(Yes RISC OS (certainly 3.10 and later) allows embedded NULs in environment
variables)

The stuff after the \0 is getting lost because perl is using a C getenv call
to get the value of the environment variable, and C is taking the first \0
it meets as the end of the string.

I've not looked at the source code for some months, but I suspect that if
you iterate over %ENV first (eg keys %ENV; in a void context) you'll get
the NUL byte (as the %ENV iterator will attempt to read in the whole
environment using code in riscos.c adapted from the VMS port)
You may also encounter fun and games (unexpected results unless you
understand how Unix stores environment variables) if you use keys to %ENV
with = in them.

It would be possible to make perl read in embedded \0s in environment
variables, but it didn't seem like a good idea because it increases the
amount of custom RISC OS code for little reason, which would make merging
the port into the main source tree slightly harder.

Nick

Reply via email to