Expand ENV var within another ENV var 
Author Message
 Expand ENV var within another ENV var

HELP.  using one var to setup multipe vars as follows:

$ENV{LOCALPATH} = /opt/perfmet;
$ENV{LIB} = $ENV{LOCALPATH}/lib;
$ENV{CONF} = $ENV{LOCALPATH/conf;
$ENV{BIN} = $ENV{LOCALPATH}/bin;

etc...

program looks for file in CONF but fails to find it:

open(CONF, "<$ENV{CONF}/cpu.cfg") or die "Reason: $!\n";

error: no such file ...

added debug to print env vars:

print "ENV{LOCALPATH} = $ENV{LOCALPATH}\n";
print "ENV{CONF} = $ENV{CONF}\n";

OUTPUT:

ENV{LOCALPATH} = /opt/perfmet
ENV{CONF} = $ENV{LOCALPATH}/conf

It seems that it doesn't automatically expand the LOCALPATH variable.

Any idea how to make this work?



Mon, 29 Aug 2005 13:06:54 GMT  
 Expand ENV var within another ENV var

Quote:
> HELP.  using one var to setup multipe vars as follows:

> $ENV{LOCALPATH} = /opt/perfmet;

This doesn't compile.  Show your real code.

[snip]

Anno



Mon, 29 Aug 2005 13:19:44 GMT  
 Expand ENV var within another ENV var

Quote:

> HELP.

#!/usr/bin/perl -Tw

use strict;
use warnings;

Quote:
> It seems that it doesn't automatically expand the LOCALPATH variable.

{1} perl -e '$ENV{LOCALPATH} = /opt/perfmet;$ENV{LIB} = $ENV{LOCALPATH}/lib;'
Bareword found where operator expected at -e line 1, near "/opt/perfmet"
        (Missing operator before perfmet?)
syntax error at -e line 1, near "/opt/perfmet"
Execution of -e aborted due to compilation errors.

{2} perl -e '$ENV{LOCALPATH} = "/opt/perfmet";$ENV{LIB} = "$ENV{LOCALPATH}/lib"; print $ENV{LIB}'
/opt/perfmet/lib

Quote:
> Any idea how to make this work?

 I seriously doubt that the code that you showed is the code you're
using; anyways, look at my example and you'll get it right (hint: use "
and not ').

--
# Per scientiam ad libertatem! // Through knowledge towards freedom! #

    perl -e'print$_{$_} for sort%_=`lynx -source svanstrom.com/t`'



Mon, 29 Aug 2005 13:52:58 GMT  
 Expand ENV var within another ENV var

Quote:

> HELP.  using one var to setup multipe vars as follows:

> $ENV{LOCALPATH} = /opt/perfmet;
> $ENV{LIB} = $ENV{LOCALPATH}/lib;

You are dividing the value of $ENV{LOCALPATH} by lib.
Use quotes instead or concatenate the individual pieces of your text.

Besides, lib is a bareword and perl should have given you an error message.

jue



Mon, 29 Aug 2005 15:56:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Unix shell env var question ???

2. env var question

3. Help, file tests & PATH env var

4. Evaluating a var within a var from read file

5. no database driver specified and DBI_DSN env var not set

6. $ENV(VAR) problem!

7. undef of $ENV{VAR} used by a called script

8. ??? set a local env var in perl script

9. get Env var, Post and Get in Win95

10. ENV var with email address from browser

11. How to set 'env'-var in perl

12. HELP: CGI can't find PERL5LIB env var

 

 
Powered by phpBB® Forum Software