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

Hi monks , I really need your help on this : I have the following function that would grep for oracle errors and exit if catch an error , however , I need to ignore only one error which is the following :
ERROR at line 1: ORA-00001: unique constraint (blablablabla) violated
How ever with my current script , I am catching all ERROR, here is my script :
package Verify; sub chkLogs ( $ ) { my $LogFileNm = shift; open ( logHndl, "$LogFileNm" ) or die ("Failed to open $LogFileNm" +); while(<logHndl>) { # # grep for keyword ERROR or ORA-ERR # push(@errors, grep (/ERROR|ORA-ERR|Fail|Unable/i, $_)); } close(logHndl); if ( $#errors > -1 ) { print "FATAL: ended with the following errors\n"; for( my $idx = 0; $idx < $#errors + 1; $idx ++ ) { print "$errors[$idx]\n"; } exit(10); } } 1;
Can someone help? thanks

Replies are listed 'Best First'.
Re: regex issue
by dragonchild (Archbishop) on Apr 26, 2004 at 16:14 UTC
    You're right. You do catch all errors. If you want to exclude an error from being caught, you need to write some logic to exclude that error.

    You'll probably want to add another grep in this line:

    push @errors, grep (## EXCLUSION LOGIC HERE ##), grep (/ERROR|ORA-ERR|Fail|Unable/i, $_);

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Re: regex issue
by Plankton (Vicar) on Apr 26, 2004 at 16:19 UTC
    Why not just do something like this ...
    while(<logHndl>) { next if /^ORA-00001: unique constraint (blablablabla) violated +/ ; # # grep for keyword ERROR or ORA-ERR # push(@errors, grep (/ERROR|ORA-ERR|Fail|Unable/i, $_)); }

    Plankton: 1% Evil, 99% Hot Gas.