nathaniels has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Elements added to hash in for loop
by LanX (Saint) on Dec 13, 2013 at 03:42 UTC | |
by AnomalousMonk (Archbishop) on Dec 13, 2013 at 10:59 UTC | |
by LanX (Saint) on Dec 13, 2013 at 15:15 UTC | |
by AnomalousMonk (Archbishop) on Dec 13, 2013 at 20:39 UTC | |
by nathaniels (Acolyte) on Dec 14, 2013 at 23:56 UTC | |
by AnomalousMonk (Archbishop) on Dec 15, 2013 at 00:27 UTC | |
by nathaniels (Acolyte) on Dec 15, 2013 at 16:49 UTC | |
by nathaniels (Acolyte) on Dec 13, 2013 at 04:27 UTC | |
|
Re: Elements added to hash in for loop
by 2teez (Vicar) on Dec 13, 2013 at 05:10 UTC | |
|
Re: Elements added to hash in for loop
by Laurent_R (Canon) on Dec 13, 2013 at 07:51 UTC |