array question (grep -v on array)

N

NetComrade

Hi,

I have an output of errors fed into an array, after which I only look
at things I care about and put them in a different array:

@oracle_errors =
grep(/ORA-/||/neededarchiving/||/FULL/||/archival/||/Standby/||/deadlock/,@output);

However, I would like to have (yet another array), e.g. @ignore_errors
which will contain values such as
ORA-error can be ignored
ORA-error2 can be ignored

How can I set that up?

Alternatively, (if simpler), i'd like to add some kind of 'grep -v'
functionality to my grep command (but the array method seems sweeter).

Thanks.
........
We use Oracle 8.1.7.4 on Solaris 2.7 boxes
remove NSPAM to email
 
B

Brian McCauley

I have an output of errors fed into an array, after which I only look
at things I care about and put them in a different array:

@oracle_errors =
grep(/ORA-/||/neededarchiving/||/FULL/||/archival/||/Standby/||/deadlock/,@output);

However, I would like to have (yet another array), e.g. @ignore_errors
which will contain values such as
ORA-error can be ignored
ORA-error2 can be ignored

What do you mean by that? What would be the desired semantics of
@ingore_errors?

If you are talking about an analogue of gnugrep -vf then I'd assume
@ignore_errors was an array of regex (all of which must be unmatched).
How can I set that up?

You could combine the patterns into one...

my $ignore_error_pattern = join '|', map "(?:$_)", @ignore_errors;
$ignore_error_pattern = qr/$ignore_error_pattern/;

....and then use...

my @oracle_errors = grep !/$ignore_error_pattern/, @output;

However, whilst this may look elegant, it turns out that it is not
efficient.

You are better off just doing it with explicit nested loops.

That is, unless you really don't need @ignore_errors to be an arbirary
array of regex.

If you can instead make @ignore_errors be a simple array of strings
that are going to looked for in a easily recognied place in the line
(like, say, at the first ocurance of 'ORA-') there's a much more
efficient solution.

my %ignore;
@ignore{@ignore_errors}=();

my @oracle_errors = grep { ! ( /(ORA-\S+)/ && exists $ignore{$1) ) } @output;
We use Oracle 8.1.7.4 on Solaris 2.7 boxes

I drive a Ford Escort on the LHS of the road :)

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top