Ask a Question related to PERL Miscellaneous, Design and Development.
-
NetComrade #1
array question (grep -v on array)
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
NetComrade Guest
-
Converting an XML Array to a multi-level array
I have an array assigned to a data grid such as: private var myIngredients:Array = new Array( <item ln1="Plain" sn="plain" ln2="(3 cups)... -
[newbie]saving and reading array of associative array
i'm looking for examples of saving to file and reading back an array of associative array, in a ruby like way. saying i have something like : ... -
array data matches but array created in loop doesn't work
I have the exact same data in two arrays, but only the array created like so will work: $spaw_imglibs = array( array( 'value' =>... -
#24897 [Com]: array_multisort() will reindex the array but not if array length is 1
ID: 24897 Comment by: franklin_se at hotmail dot com Reported By: chro at sokrates dot uio dot no Status: ... -
#24897 [Opn->Asn]: array_multisort() will reindex the array but not if array length is 1
ID: 24897 Updated by: sniper@php.net Reported By: chro at sokrates dot uio dot no -Status: Open +Status: ... -
Brian McCauley #2
Re: array question (grep -v on array)
[email]andreyNSPAM@bookexchange.net[/email] (NetComrade) writes:
What do you mean by that? What would be the desired semantics of> 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
@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).
You could combine the patterns into one...> How can I set that up?
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;
I drive a Ford Escort on the LHS of the road :-)> We use Oracle 8.1.7.4 on Solaris 2.7 boxes
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
Brian McCauley Guest



Reply With Quote

