Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Searching text files

by aquarium (Curate)
on Sep 14, 2006 at 18:26 UTC ( [id://572971]=note: print w/replies, xml ) Need Help??


in reply to Searching text files

not sure if you need anything fancy....something like (unix code)
grep $phone_num file1 file2 file3
...sitting behind a primitive gui should do it. you can get a (standalone..without cygwin) grep.exe for windows as well. if you must call it from perl then just wrap inside backticks and assign the output to a variable
my $result = `grep $phone_num file1 file2 file3`; if($result) { print "number is in blocked list"; }
the hardest line to type correctly is: stty erase ^H

Replies are listed 'Best First'.
Re^2: Searching text files
by planetscape (Chancellor) on Sep 14, 2006 at 22:45 UTC
Re^2: Searching text files
by Not_a_Number (Prior) on Sep 14, 2006 at 19:04 UTC
    you can get a <...> grep.exe for windows as well...

    Why bother, when windows has a native tool that serves a similar purpose:

    my $result = `findstr $phone_num file1 file2 file3`; if ( $result ) { print "DO NOT CALL $phone_num\n"; } else { print "You can annoy $phone_num with your gratuitous cold calling\n" +; }

      grep and findstr are both O(n) linear searches. Maybe I'm missing something here, but I think that's what the OP is trying to avoid; a linear search that takes O(n) time to fail.


      Dave

        forget O(n) etc. the original poster was slurping the whole files into memory, which was the cause of the slowness. grep will match the number in the 3 files (several megs total) in about a second....which surely meets the criteria for response time. the poster is a beginner, so would be best for them to have a one liner with a 1 second response time..rather than complicated code with at best 0.5 second response time.
        the hardest line to type correctly is: stty erase ^H
        grep and findstr are both O(n) linear searches...

        Err, yes. But could you explain why you posted this as a reply to my node, which is explicitly tagged as a reply to aquarium rather than a solution to the OP's problem?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found