http://www.perlmonks.org?node_id=79803


in reply to Search and replace on a 130000+ line file.

Here is my quick and nasty solution. This loads the first file into a hash so it may use up lots of memory. Though if it too is 130,000 lines that is only a few megabytes.

Should run fast! (Tested also ;-)

use strict; die "Syntax: $0 <names> < djb-file > output-file" unless @ARGV == 1; my %name_to_ip; open(IN, "<".shift) or die; while (<IN>) { chomp; my ($ip, $name) = split /:/; $name_to_ip{$ip} = $name; } close IN or die; while (<>) { chomp; my ($name, $ip) = split /:/; print $name_to_ip{$ip} || $name, ":", $ip, "\n"; }