Re: Searching large files with a regex and a list



Channing wrote:

I would like some suggestions (constructive) on some code I'm writing.
My Perl is rusty and that's reflected in the sample I'm posting. Here
is what I have to tackle. I have Gig files to parse for two different
RegEx's. Within those RegEx's there is a variable that is a list of
18,000+ numbers. I'm looking for some suggestions on what I can do to
speed things up, or at least make things better.

Thanks in advance for your time.

------- Code Begin ---------
#!/usr/bin/perl

my $match=0;
my $nonMatch=0;

open(DN_LIST, "<","big_list");
my @list = <DN_LIST>;
@list=sort(@list);
close(DN_LIST);
foreach (@list)
{
chomp;
s/ //g;
}
@list = join('|',@list);

Joining multiple RegEx into one like this is _less_ efficient than
simply looping over @list, which is why the answer given in the FAQ
(yes, your question is a FAQ) does not suggest doing so. (It does
suggest using qr// to precompile the RegEx though...

$_=qr/$_/; # Inside your loop

.



Relevant Pages

  • Re: Sequence matching exercise
    ... The program should exit ... Then write a program to support the parse ... your next homework assignments. ... C++ Faq: http://www.parashift.com/c++-faq-lite ...
    (comp.lang.c)
  • Re: Using a for() statement to create a variable??
    ... > I have a form that is dynamiclly generated from a database. ... > CGI module, I'm trying to parse the parameters returned, but since the ... please see the FAQ and google. ...
    (comp.lang.perl.misc)
  • Re: Text File parsing
    ... Imran wrote: ... I have to parse a text file and get some value in that. ... C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: ... Other sites: http://www.josuttis.com -- C++ STL Library book ...
    (comp.lang.cpp)
  • Re: Using OSVERSIONINFOEX to identify 2000 Workstation vs 2000 Ser
    ... parse - basically it's a messy thing to try to do. ... Dave ... MVP VC++ FAQ: http://www.mvps.org/vcfaq ...
    (microsoft.public.vstudio.general)