gpt4 book ai didi

perl - 使用内置 Perl 模块捕获短主机名?

转载 作者:行者123 更新时间:2023-12-03 18:38:07 25 4
gpt4 key购买 nike

有没有更清洁的方法

use Sys::Hostname qw(hostname);

my $hostname = hostname();
$hostname =~ s/\.domain//;

基本上,是否可以在不运行两个 $hostname 的情况下将主机名剥离为其短名称?作业和没有额外的模块?

最佳答案

使用 Sys::Hostname :

use Sys::Hostname;

my ($short_hostname) = split /\./, hostname(); # Split by '.', keep the first part

使用系统主机名命令:
chomp(my ($short_hostname) = `hostname | cut -f 1 -d.`);

关于perl - 使用内置 Perl 模块捕获短主机名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43404275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com