I have set the WORKAREA to some path and in Perl code I have defined like this:
eval 'exec $ENV{'WORKAREA'}/some/path'
if 0;
I am getting error that path $ENV{'WORKAREA'}/some/path
is not defined. Anyone know to define this?
I'm not sure what you are copying there, but there are a few problems.
First, look inside the string that you give to eval
. It's not valid Perl:
exec $ENV{'WORKAREA'}/some/path
You're trying to construct the string that represents the path to the program you want to exec
, so quote the whole thing (like any other string):
exec "$ENV{'WORKAREA'}/some/path"
or even better, use generalized quoting so you won't have to escape something later:
exec q($ENV{'WORKAREA'}/some/path)
Note that I used q()
here. You don't want that string to interpolate because that variable will have already been interpolated by the string you give to eval
:
eval "exec q($ENV{'WORKAREA'}/some/path)"
I'm not sure why you eval
this though. Maybe you think that the eval
will shield you from some magic. But, exec
isn't doing anything that magical. It's presence in your program shouldn't affect anything else:
if( 0 ) { # why are you doing this?
exec "$ENV{'WORKAREA'}/some/path"
}