Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: File Search And Compare

by Kozz (Friar)
on Feb 18, 2002 at 21:31 UTC ( #146254=note: print w/ replies, xml ) Need Help??


in reply to File Search And Compare

PyroX:
I think that what you're really looking for is a hash-based solution. If you were to tie() a hash using the DB_File module (if indeed this is a real MONSTER of a file), this would use the disk rather than memory (correct me if I'm wrong, most wise monks!).

Perhaps something like

open(FILE, "< /var/log/everything") or die "Could not read file: $!"; while($input=<FILE>){ if($input =~ /fwa/i){ $tied_hash_ref->{ lc($input) }++; } }
Notice that I've used lc() to lower-case the text in the line. Otherwise the hash would contain separate values for "fwa100" vs "FWA100" vs "fWa100". Remove this if you desire to keep them separate.

You could then iterate over this tied hash, printing the key/value pairs. Though to be honest, I've not had a great need for DB_File much, and would welcome other monks to contribute usage examples. ;)


Comment on Re: File Search And Compare
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-11-22 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (120 votes), past polls