my %hosts = map{ split /\s+/, $_, 2 }<DATA>; # Or substitute your favourite filehandle here. __DATA__ host1 1.1.1.1 host2 1.2.3.5
Note, however, that the format you give is not the standard format for hosts files. The usual format is more like...
# IP Masq gateway: 192.168.0.80 pedestrian # Primary desktop: 192.168.0.82 raptor1 # Family PC upstairs: 192.168.0.84 trex tyrannosaur family # Domain servers: 205.212.123.10 dns1 brutus 208.140.2.15 dns2 156.63.130.100 dns3 cherokee
This is easy enough to read too...
open HOSTS, "</etc/hosts"; # Or "<C:\\WINDOWS\\hosts"; my %hosts = map{ my $ip, $hn, @hn; if (not /^\s*#/) { chomp; s/\s*#.*$//; ($ip, @hn) = split /\s+/, $_; } map { $_ => $ip }, @hn; }<HOSTS>;
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
In reply to Re: newbie hasher
by jonadab
in thread newbie hasher
by prodevel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |