Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by ncw (Friar)
on May 11, 2001 at 22:27 UTC ( #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? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2022-01-19 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?