in reply to RegEx Problem?

I think it's going to depend on the size of your file, but I think that if the file isn't too large, slurping it in and doing a foreach isn't going to be the worst. Since all your data is seperated by newlines, why would you bother with stuffing all that data in to a database? You could do something like:

use strict; my $line; open FH, $ARGV[0] or die "Couldn't open input file" while ($line = <FH>){ print $line if $line =~ /*I*like*foo*/; } close FH;

If you're on a *nix system, and all you want to do is print those lines, wouldn't it be easier to just use the grep utility?

There is no emoticon for what I'm feeling now.

Replies are listed 'Best First'.
Re: Re: RegEx Problem?
by bart (Canon) on Feb 25, 2003 at 08:03 UTC
    I think the regex should actually look like
    /I.*like.*foo/
    which can be constructed out of the searchstring using
    $re = join '.*', map quotemeta, split ' ', $search;
      You're rght, it probably should. However I wasn't sure if the person who posted was looking for that exact string or using it as a pseudo string.

      There is no emoticon for what I'm feeling now.

Re: Re: RegEx Problem?
by OverlordQ (Hermit) on Feb 25, 2003 at 06:41 UTC
    Since this is just a piece of a larger program, I'd rather keep it all in Perl if possible. And as for file sizes, a similar file that is 6328 lines is about 564k, so figuring ~7.3 million lines, that's about 666075395 bytes, so about 635 MB all together (correct me on my math if I'm wrong).

      As a general rule-of-thumb, a database that is more than 1 MB in size should be kept out of a flat-file and into a real database. Some people suggest even less than that.

      And when in a discussion about flat-file vs. real databases, you really ought to mention DBD::SQLite.

      ----
      Reinvent a rounder wheel.

      Note: All code is untested, unless otherwise stated

        This is the second time I've seen DBD::SQLite mentioned in two days. I looked at the CPAN page, and the project homepage, but didn't find too much information about how to use it with perl. Would you be willing to post a simple example of how somebody would use it in an instance like this one?