Dear Monks,
I am new to hashes etc and wondered if you could help. I have two arrays placed in a hash: one contains numbers, the other contains + and - signs related to each number. I have a third array not in the hash which i am using to compare to the numbers in the hash and extract the corresponding sign when they match. I know that hashes are mixed up (e.g. not in insertion order), but when my number matches, not only would I like to extract the corresponding sign, but i would also like to extract the next sign in the sequence e.g
$i and
$i+1 - this is the part that i'm confused about. Here's my code below - hope you can help !
my %hash = map { $numbers[$_] => $signs[$_]} 0 .. $#numbers;
while (($key, $value) = each (%hash)) {
if (@new_numbers) {
for (my $i=0; $i<@new_numbers; $i++) {
if ($key == $new_numbers[$i]) {
print "$value \t $new_numbers[$i]"; # th
+is prints the sign and the number it matches to
}
}
}
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.