in reply to While loop and LAST

The problem is that each continues from where it last returned unless you reset the iterator using (say) keys %hash. Which means that you are not searching the complete hash each time around your outer loop.

But, before you go fixing that; why are you searching a hash in the first place? That (as Mr.Wall would have it) is like "buying and Uzi and using it to club your enemy to death".

You should be able to just do:

foreach my $row ($te->rows) { $tracking_code = $ { $row }[0]; $job_title = $ { $row }[1]; $location = $ { $row }[2]; $date_posted = $ { $row }[3]; if( exists $job_categories{ $job_title } ) { $department = $job_categories{ $job_title }; } else { print "no match"; } }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: While loop and LAST
by Kenosis (Priest) on Nov 02, 2013 at 06:19 UTC

    The job titles from the parsed table are more verbose than the hash keys--which are key phrases that may be found in those titles, thus the OP's regexing in the while loop. For example, in one case the OP is looking for the phrase "account manager" (a hash key) in the job title "Territory / Field Sales Account Manager Mid-Enterprise GEO".

      Then resetting the hash iterator will probably fix his problem.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      Correct. I was (still am) thinking that this can become a more generic approach to the problem. Eventually the hash can be maintained outside the script, either as something a third party supplies or other managers just maintain.

      If this list gets to 500 key value pairs I'm not sure.