File: read_host.pl

package info (click to toggle)
libfile-read-perl 0.0801-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 160 kB
  • sloc: perl: 121; makefile: 2
file content (12 lines) | stat: -rw-r--r-- 399 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/perl
use strict;
use Data::Dumper;
use File::Read;

# read /etc/hosts and put the the contents in a hash which gives the IP 
# address of the hostnames, thus providing an el-Cheapo resolving thingy :)

my %addr = map { my ($ip,@names) = split /\s+/; map { $_ => $ip } @names } 
    read_file({ aggregate => 0, skip_blanks => 1, skip_comments => 1 }, '/etc/hosts');

print Dumper(\%addr);