phimtau123 has asked for the wisdom of the Perl Monks concerning the following question:

So if i have a Sub function that would read the content of a file and parse it into a database. Now if a file containing the word CLEAR, I want to skip that file and go to the next. Meaning file that have the word CLEAR will not be entering into database. How can i do this?

Replies are listed 'Best First'.
Re: Filter File that have certain word
by Joost (Canon) on Jun 06, 2007 at 20:13 UTC
Re: Filter File that have certain word
by GrandFather (Saint) on Jun 06, 2007 at 22:51 UTC

    What have you got at the moment (just the half dozen lines that deal with iterating over files)? It may be that all you have to do is:

    while (...) { open INFILE, '<', ...; my $buffer = do {local $/; <INFILE>}; next if $buffer =~ /CLEAR/; ... } continue { close INFILE; }

    Prints:


    DWIM is Perl's answer to Gödel
Re: Filter File that have certain word
by swampyankee (Parson) on Jun 07, 2007 at 03:27 UTC

    What is the structure of the file? What is the context in which CLEAR can appear? What database are you using?

    For Oracle or DB2, and presumably any other database using SQL, you could do all the inserts, and then perform a ROLLBACK if a record containing "CLEAR" is found.

    emc

    Any New York City or Connecticut area jobs? I'm currently unemployed.

    There are some enterprises in which a careful disorderliness is the true method.

    —Herman Melville