Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

raku - Getting absolute path to perl executable for the current process

Is there a way to get an absolute path to the Perl executable for the current process?

$^X will give me the Perl executable name, but the doc states that it will sometimes be a relative path, and this seems to be true on OS X for example.

ExtUtils::MakeMaker seems to have some magic to find the absolute path, since the Makefile it generates on my OS X contains

PERL = /usr/local/bin/perl
FULLPERL = /usr/local/bin/perl

but I have no idea how it does this or whether the magic is readily accessible to others.

EDIT: Thanks Borodin for the $Config{perlpath} tip. Grepping for this in ExtUtils, I found this tidbit in ExtUtils::MM_Unix::_fixin_replace_shebang, which I guess is what MakeMaker uses to replace #!perl with the correct shebang line.

if ( $Config{startperl} =~ m,^#!.*/perl, ) {
    $interpreter = $Config{startperl};
    $interpreter =~ s,^#!,,;
}
else {
    $interpreter = $Config{perlpath};
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think what you're looking for is $Config{perlpath}.

If you want your code to be very portable you may have to append a file type to that value; this is described in the perlport documentation. Otherwise all you need is this:

use Config;
my $perl = $Config{perlpath};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...