String::ShortHostname - extracts the first field from an FQDN
version 1.000
This module will take a fully qualified domain name and return the first field which is normally the short hostname (mostly equivalent to hostname -s on Linux).
hostname -s
use String::ShortHostname; my $fqdn = 'testhost.example.com'; my $hostname = short_hostname( $fqdn ); print $hostname; # prints 'testhost'
If an IPv4 address is passed to it, it will be returned verbatim. Otherwise the logic is simply to return everything before the first ..
.
Alternatively, it can be used in an OO way, but without much benefit:
use String::ShortHostname; my $fqdn = 'testhost.example.com'; my $short = String::ShortHostname->new( $fqdn ); my $hostname = $short->hostname; print $hostname; # prints 'testhost'
Please report any bugs or feature requests in the issues section of GitHub: https://github.com/Q-Technologies/perl-String-ShortHostname. Ideally, submit a Pull Request.
Matthew Mallard <mqtech@cpan.org>
This software is copyright (c) 2019 by Matthew Mallard.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install String::ShortHostname, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::ShortHostname
CPAN shell
perl -MCPAN -e shell install String::ShortHostname
For more information on module installation, please visit the detailed CPAN module installation guide.