Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Search and replace on a 130000+ line file.

by ncw (Friar)
on May 11, 2001 at 22:27 UTC ( [id://79803]=note: print w/replies, xml ) Need Help??


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"; }

Replies are listed 'Best First'.
Re: Re: Search and replace on a 130000+ line file.
by sierrathedog04 (Hermit) on May 11, 2001 at 23:05 UTC
    For whatever reason, the line:
    open(IN, "<".shift) or die;
    doesn't work for me in ActiveState Perl 5.6 /NT workstation when I call the above program as
    perl tempo.pl ip.dat djb.dat

    However, the program works great when I replace that line with:

    open(IN, "<ip.dat") or die;
    and call it as:
    perl tempo.pl djb.dat

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://79803]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-19 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found