in reply to Re: Parsing variables from login scripts
in thread Parsing variables from login scripts

I've been working way too many hours to see this clearly. Here's what's not working so well, so far... Ok, let's see if I can format this correctly:
___DATA___ MY_DIR=~/temp/module export MY_DIR MY_BIN=$MY_DIR/bin MY_DATA=$MY_DIR/data export MY_BIN MY_DATA __temp.pl__ #! /usr/local/bin/perl require "testpack.pm"; testpack::import(); print "DIR $DIR\n"; __testpack.pm__ package testpack; sub import { $conf_file = "conf.sh"; open (FILE, $conf_file) || die "Cant open file. \n"; while (<FILE>) { if (! (/^\W/ || /^export/)) { # ign. cmnts & ws chomp; print "$_\n"; my ($var, $value) = split(/\s*=\s+/, $_, 2); if ($value =~ s/^\$(\w+)//) { $value .= $env_var{$1} || ''; } $env_var{$var} = $value; my ($caller_package) = caller; *{"${caller_package}::${var}"} = $value; } # end if } # end while } # END import() definition

Replies are listed 'Best First'.
RE: RE: Re: Parsing variables from login scripts
by chromatic (Archbishop) on Jul 29, 2000 at 04:15 UTC
    Your split doesn't match your data -- the whitespace before the = is optional (zero or more instances) but required after the sign (one or more instances). Change the + to a * and it will probably work better.

    You might put a debugging line after the split, just to see what's in $var and $value: print "\$var is ->$var<-\t\$value is ->$value<-\n"; Besides that, I had things backwards in the original version of my code. Try this instead: $value = $env_var{$1} . $value; That way, it won't go in the wrong place. Oops!