Hello!

I've been working on this for a while and I'm absolutely dumbfounded. This function is supposed to search through a hash created from a database pull by searching through the primary keys. However, after an iteration through the loop two entries get added: 0 => {}, 1 => {}. Here's the function:

use DBI; use List:Util; use Math::Complex; my %CLAUSES; sub next_clauseid { my $current_id = @_; foreach my $id ( keys %CLAUSES ) { if ( $CLAUSES{ $id }{ lineno } == $CLAUSES{ $current_id }{ li +neno } and $CLAUSES{ $id }{ clauseno } == ($CLAUSES{ $current_id +}{ clauseno } + 1) ) { return $id; } } return 0; }

Some sample data in %CLAUSES

10950, { behav_behaver => undef, behavioural => undef, character => "MARS", clause => "Did you just swear?", clauseid => 10950, clauseno => 1, exist_existent => undef, existential => undef, lineid => 181, lineno => 181, mat_actor => undef, mat_goal => undef, material => undef, men_phenom => undef, men_senser => undef, mental => undef, rel_attribute => undef, rel_carrier => undef, rel_identified => undef, rel_identifier => undef, relational_attr => undef, relational_ident => undef, verb_sayer => undef, verb_target => undef, verbal => undef, }, 10736, { behav_behaver => undef, behavioural => "", character => "BRIAN", clause => "Yeah, yeah.", clauseid => 10736, clauseno => 1, exist_existent => "", existential => "", lineid => 7, lineno => 7, mat_actor => "", mat_goal => "", material => "", men_phenom => "", men_senser => "", mental => "", rel_attribute => "", rel_carrier => "", rel_identified => "", rel_identifier => "", relational_attr => "", relational_ident => "", verb_sayer => "", verb_target => "", verbal => "", }, 10862, { behav_behaver => undef, behavioural => undef, character => "BRIAN", clause => "I'll call the cops.", clauseid => 10862, clauseno => 1, exist_existent => undef, existential => undef, lineid => 121, lineno => 121, mat_actor => undef, mat_goal => undef, material => undef, men_phenom => undef, men_senser => undef, mental => undef, rel_attribute => undef, rel_carrier => undef, rel_identified => undef, rel_identifier => undef, relational_attr => undef, relational_ident => undef, verb_sayer => undef, verb_target => undef, verbal => undef, },

Thanks for your help!


In reply to Elements added to hash in for loop by nathaniels

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.