1

I have a file "temp.txt" containing

var1=hello
var2=ello
var3=mello
....and a long list

in unix shell we can simply use . temp.txt is use all the variables in the file..

do we have a similar function in perl or any work around..

I tried a workaround

$ cat checkDOTfuctionOFunix.ksh
#!/bin/ksh
. /export/home/temp.txt
#export

/export/home/checkDOTfuncPRINTSinPERL.pl

$ cat /export/home/checkDOTfuncPRINTSinPERL.pl
#!/usr/local/bin/perl

print "var1=$ENV{var1} \n\n var2=$ENV{var2} \n\n";

but this wont work unless I export each value which can be done with simple sed -e 's/^/export/ but I prefer not to do this. please help :)

Thomas8
  • 1,117
  • 1
  • 11
  • 22
Kaze..Sujan
  • 116
  • 1
  • 8

2 Answers2

1
set -a
. temp.txt
set +a
./checkDOTfuncPRINTSinPERL.pl

with set -a as explained here, all variable assignments promote the variable to an environment variable.
Here some doc to shell set options.

Community
  • 1
  • 1
Thomas8
  • 1,117
  • 1
  • 11
  • 22
  • Cheers!! this works.. but is there a command like this in perl... I would like to avoid calling the perl script from ksh shell script and directly use `temp.txt` file in `checkDOTfuncPRINTSinPERL.pl` – Kaze..Sujan Feb 05 '15 at 09:47
0

This is now possible in Perl with the Env::Modify module.

use Env::Modify 'source';
source("temp.txt");     # like saying  . temp.txt  in the shell
.. env settings in  temp.txt  are now available to Perl ...
mob
  • 117,087
  • 18
  • 149
  • 283