[GRASS5] $LOCATION or not $LOCATION ?

Glynn Clements glynn.clements at virgin.net
Thu May 16 07:17:09 EDT 2002


Eric G. Miller wrote:

> > Like Bourne shell, Perl has backticks. But, unlike Bourne shell,
> > Perl's backticks don't strip the newline from the output. So, using:
> > 
> > 	$gisdbase=`g.gisenv get=GISDBASE`
> > 
> > includes the trailing newline. If you can figure out how to remove it,
> > that may be simpler than the loop.
> 
> $ENV{GISDBASE} = `g.gisenv get=GISDBASE`;
> chomp $ENV{GISDBASE};
> $ENV{LOCATION_NAME} = `g.gisenv get=LOCATION_NAME`;
> chomp $ENV{LOCATION_NAME};
> $ENV{MAPSET} = `g.gisenv get=MAPSET`;
> chomp $ENV{MAPSET};
> $ENV{LOCATION} = "$ENV{GISDBASE}/$ENV{LOCATION_NAME}/$ENV{MAPSET}";

Normally, it's preferable to use "normal" variables rather than
environment variables, as environment space is a limited resource (and
shared with the argument list, so consuming environment space reduces
the maximum length of an argument list).

Environment variables should only be used if you need to update an
existing script which already refers to environment variables. They
shouldn't be used for new scripts.

-- 
Glynn Clements <glynn.clements at virgin.net>



More information about the grass-dev mailing list