Net::protoent(3pm)
β¨ Net::protoent β¨
okay so bestie, welcome to the Net::protoent(3pm) page from the Perl Programmers Reference Guide β it's literally the by-name interface to Perl's built-in getproto*() functions. vibe check passed, let's go π
π NAME π
Net::protoent β by-name interface to Perl's built-in getproto*() functions. periodt.
πΈ SYNOPSIS πΈ
here's the code, exactly as it's giving:
use Net::protoent;
my $p = getprotobyname(shift || 'tcp') || die "no proto";
printf "proto for %s is %d, aliases are %s\n",
$p->name, $p->proto, "@{$p->aliases}";
use Net::protoent qw(:FIELDS);
getprotobyname(shift || 'tcp') || die "no proto";
print "proto for $p_name is $p_proto, aliases are @p_aliases\n";
π¦ DESCRIPTION π¦
okay so the default exports of this module override the core getprotoent(), getprotobyname(), and getnetbyport() functions β they replace them with versions that return Net::protoent objects. they take default second arguments of "tcp". this object has methods that return the similarly named structure field name from the C's protoent structure from netdb.h; namely name, aliases, and proto. the aliases method returns an array reference, the rest scalars. iykyk β¨
You may also import all the structure fields directly into your namespace as regular variables using the :FIELDS import tag. (note that this still overrides your core functions.) access these fields as variables named with a preceding p_. thus, $proto_obj->name() corresponds to $p_name if you import the fields. array references are available as regular array variables, so for example @{ $proto_obj->aliases() } would be simply @p_aliases. π«Ά
The getproto() function is a simple front-end that forwards a numeric argument to getprotobyport(), and the rest to getprotobyname(). that's the exact function name on the page, bestie π
To access this functionality without the core overrides, pass the use an empty import list, and then access function functions with their full qualified names. on the other hand, the built-ins are still available via the CORE:: pseudo-package. main character energy, no cap π₯
π§ NOTE π§
while this class is currently implemented using the Class::Struct module to build a struct-like class, you shouldn't rely upon this. ngl, don't build your whole personality on that implementation detail β it could change π
π AUTHOR π
Tom Christiansen π
mwah π this page is from perl v5.42.3, dated 2026-11-03, and it's the Net::protoent(3pm) page. bye bestie π«Ά
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms