First rule of fixing broken perl code. Apply 'use strict;' and 'use warnings;'. This gives a lot of warnings and errors with your code, which would warrant sorting first.

It looks like you're doing a fairly substantial number of slightly horrible things. I would imagine that if you did use strict and warnings, your problem would vanish (or become obvious. For starters - populating an array by setting $n.

my @jobvar_list = ( "senior", "exec" );

Will do exactly the same thing. Even better, you could use a hash, so you never needed to iterate through one list, and reference another list.

my %jobvar_list = ( 'senior' => 'Senior', 'exec' => 'Exec' ); my $quick_jobtype = "exec"; foreach my $temp_jobvar ( keys %jobvar_list ) { print "$temp_jobvar, $jobvar_list{$temp_jobvar}\n"; if ( $temp_jobvar eq $quick_jobtype ) { print "$temp_jobvar matches $quick_jobtype"; my $sortby = " WHERE jobtype like '%$jobvar%' and active='yes' AND + jobstatus!='suspend' ORDER BY dateadded DESC, jobtitle ASC"; print $sortby; } }

I think it must be that 'if' clause that's causing you problems - what is it trying to do? It sounds like it's evaluating but never working, and therefore not running that 'sortby' and 'Build_Lists_Both' segments of code. Which is odd, because it seems to be doing so in that sample code you posted. Is there any chance that you've tidied your code up a bit, with the job title list? that 'eq' line means that the two variables have to match precisely - no whitespace or linefeeds. Because your code _does_ run as is.


In reply to Re: Help with a loop by Preceptor
in thread Help with a loop by htmanning

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.