Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL getservbyname Function



Syntax

getservbyname NAME, PROTO


Definition and Usage

Translates the service NAME for the protocol PROTO, returning the service number in a scalar context and the number and associated information in a list context:

($name, $aliases, $port_number, $protocol_name)

This call returns these values based on /etc/services file.

Return Value

  • In scalar context undef on error otherwise service number

  • In list context empty list on error otherwise Service record (name, aliases, port number, protocol name).

Example

Try out following example:

#!/usr/bin/perl

($name, $aliases, $port_number, 
     $protocol_name) = getservbyname("ftp", "tcp");
print "Name = $name\n";
print "Aliases = $aliases\n";
print "Port Number = $port_number\n";
print "Protocol Name = $protocol_name\n";

It will produce following result

Name = ftp
Aliases =
Port Number = 21
Protocol Name = tcp



Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names