Hi Monks
How do I find out if an element exists in a normal array?
I have a normal array (@perf_array) and I am comparing it to the values of a hash array (%values). If a value from the normal array matchs any value in the hash array I parse out information from the normal array and set it as the value in another hash array with the matched value as its corresponding key. If any value in the hash array does not exist in the normal array I want to put the value in the hash array as a key value with 0 as its corresponding value
Hope the above makes sence
I am having trouble doing this
Hope you can help
Here is my code
... code here populates normal array (@perf_array)
# put the elements into a hash array
for (my $k = 0; $k <= $#perf_array; $k++) {
while( my ($oid, $perf) = each %values ) {
if ($perf_array[$k] =~ /.*\d+\s+$perf.*/) {
$perf_hash{$perf} = $perf_array[$k];
$perf_hash{$perf} =~ s/\*\s+(\d+)\s+$perf/$1/eg;
$perf_hash{$perf} =~ s/\s*$//g;
chomp $perf_hash{$perf};
}
}
}
for (my $l = 0; $l <= $#perf_array; $l++) {
$perf_array[$l] =~ s/\*\s+\d+\s+(.*)/$1/eg;
$perf_array[$l] =~ s/\s*$//g;
chomp $perf_array[$l];
while( my ($oid1, $perf1) = each %values ) {
if ( $perf1 != /$perf_array[$l]/ ) {
$perf_hash{$perf1} = "0";
print "$perf1 not found; set to $perf_hash{$perf1}\n";
}
}
}
Thanks in advance
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.