[GRASS5] $LOCATION or not $LOCATION ?

Glynn Clements glynn.clements at virgin.net
Thu May 16 04:51:14 EDT 2002


Markus Neteler wrote:

> > However, I can't absolutely rule out the possibility that something
> > may have slipped through the net. Now that you mention it, I recall
> > Markus mentioning a Perl script which needed fixing; I don't recall
> > the outcome, though.
> 
> We had problems with our *local* scripts (30 or more). Eventually
> a PERL script in GRASS also needs a fix.
> 
> Our workaround for PERL was to
> 
> #read the GRASS variables:
> open(RRR,"g.gisenv |");
> while(<RRR>){
>     chop();
>     chop();
>     @part=split(/=/,$_);
>     $part[1]=~s/\'//g;
>     $ENV{"$part[0]"}="$part[1]";
> }
> close RRR;
> $ENV{LOCATION}="$ENV{GISDBASE}/$ENV{LOCATION_NAME}/$ENV{MAPSET}";
> 
> which looks pretty complicated compared to Shell scripts.
> Is there a more elegant solution to get the environment into
> PERL (I am no PERL users).

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.

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



More information about the grass-dev mailing list