Show
Ignore:
Timestamp:
09.08.2017 19:09:28 (2 years ago)
Author:
ak19
Message:

Adding a new subroutine print_env() that may be useful for debugging env vars. It will print the values of all environment variables to STDERR if no specific ones are requested. If specific env vars are requested, it will just print their values to STDERR.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/util.pm

    r31694 r31862  
    580580} 
    581581 
     582# debug aid 
     583sub print_env { 
     584    my @envvars = @_; 
     585 
     586    if (scalar(@envvars) == 0) { 
     587    print STDERR "@@@ No env vars requested\n"; 
     588     
     589     
     590    my $output; 
     591    if (defined $ENV{'GSDLOS'} && $ENV{'GSDLOS'} =~ m/windows/) { 
     592        $output = `set`; 
     593    } 
     594    else { 
     595        $output = `env`; 
     596    } 
     597     
     598    print STDERR "@@@ Environment was:\n********\n$output\n*******\n"; 
     599    } else { 
     600    print STDERR "@@@ Environment was:\n********\n"; 
     601    foreach my $envvar (@envvars) { 
     602        if(defined $ENV{$envvar}) { 
     603        print STDERR "\t$envvar = ".$ENV{$envvar}."\n"; 
     604        } else { 
     605        $envvar = uc($envvar); 
     606        if(defined $ENV{$envvar}) { 
     607            print STDERR "\t$envvar = ".$ENV{$envvar}."\n"; 
     608        } else { 
     609            print STDERR "Env var $envvar was not set\n"; 
     610        } 
     611        } 
     612    } 
     613    print STDERR "@@@*******\n"; 
     614    } 
     615} 
    582616 
    583617