Walt Mankowski on Sat, 26 Jul 2003 11:28:13 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Environment variables


On Sat, Jul 26, 2003 at 08:12:42AM -0700, James wrote:
> I am looking for a way to use variable substitution
> with environment variables.  My /etc/environment looks
> like this:
> 
> NUM_X=6
> X1="some value"
> X2="some value"
> X3="some value"
> X4="some value"
> X5="some value"
> X6="some value"
> 
> 
> Trying to keep things dynamic, I would like to print
> out all values of X(n) by using a 'for' statement,
> which goes like this:
> 
> $num = $ENV{'NUM_X'};
> 
> for ($i = 1; $i <= $num; $i++) {
>    printf ("%15s\n", $ENV{'X[$i]'});
> }
> 
> 
> How would I go about getting the $i with 'X'
> environment variable so I can print out X1 thru X6?  

I don't understand your question.  Isn't that what your code is
already doing?  Are you trying to do it without NUM_X?  If so, you
could do that with something like 

@x_keys = grep { /^X\d+$/ } keys %ENV;
printf ("%15s\n", $ENV{$_}) for @x_keys;

Walt

Attachment: pgpTK8K17JES0.pgp
Description: PGP signature