Hi!
Maybe this way is useful for you:
use strict;
use Data::Dumper;
sub getServices{
my $file = "/etc/services";
open SVCS, $file or die "Error opening $file: $!";
my $services;
while( <SVCS> ){
my %hash;
next if $_ =~ /^\#/ or $_ =~ /^\s/;
my ($name, $port_proto) = split /\s+/, $_;
my ($port, $proto) = split /\//, $port_proto;
%hash = ( protocol => $proto, port => $port );
$services->{$name} = \%hash;
}
close SVCS;
return $services;
}
my $returned = &getServices;
print Dumper $returned;
print "Protocol for service FTP: $returned->{ftp}->{protocol}\n";
Regards