Turbo Sullivan Turbo Sullivan - 5 months ago 15x
Python Question

perl eval with back quote

I was converting a perl script into python and then I found this function which I couldn't understand.

sub set_xyz_hash {
%xyz = ();
$_ = join(' ', map { my $a = $_; $a =~ s/\'/\'\"\'\"\'/g; "'$a'" } @ARGV);
eval `XYZ_ARG0='$0' NZENV_OUTPUT='-a -p xyz' xyz $_`;

since my knowledge in perl is very limited, I couldn't understand 'eval' used in this function. can someone please help me here?

note, eval is used wth ` (back quote).


The backticks run an external command and return the output:

my $result = `ls -l`;
print $result;

Your eval line is processed exactly the same way:

my $result = `XYZ_ARG0='$0' NZENV_OUTPUT='-a -p xyz' xyz $_`;
eval $result;

It's basically fetching some Perl source from the called script and runs it.