Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Help with a loop

by frozenwithjoy (Priest)
on Jun 14, 2013 at 21:25 UTC ( #1039039=note: print w/replies, xml ) Need Help??

in reply to Help with a loop

A few comments:

You should be using: use warnings; and use strict;, because they will reveal a lot of errors (e.g., Scalar value @jobvar_list[$n] better written as $jobvar_list[$n] at ...

I added these and made the necessary changes (including declaring everything with my ... and re ran it (after commenting out the subroutine that gets called) and it seems to work fine:

#!/usr/bin/env perl use strict; use warnings; my @jobvar_list = (); my @jobname_list = (); my @jobnice_list = (); my $n = 0; $jobvar_list[$n] = "senior"; $jobname_list[$n] = " Senior"; $n++; $jobvar_list[$n] = "exec"; $jobname_list[$n] = " Executive"; $n++; my $quick_build = "listing"; my $quick_jobtype = "exec"; print "job types...<br>\n"; for ( my $st = 0 ; $st <= @jobvar_list - 1 ; $st++ ) { my $temp_jobvar = $jobvar_list[$st]; print "$temp_jobvar, $quick_jobtype...<br>\n"; if ( ( $quick_jobtype && ( $quick_jobtype eq $temp_jobvar ) ) || ( !$quick_jobtype ) ) { my $jobvar = $temp_jobvar; my $jobname = $jobname_list[$st]; my $groupfile = $jobvar; my $grouptitle = $jobname; my $sortby = " WHERE jobtype like '%$jobvar%' and active='yes' AND jobstatus!='susp +end' ORDER BY dateadded DESC, jobtitle ASC"; print "$sortby"; print "starting build lists<br>\n"; my $building_cat = "yes"; # &Build_Lists_Both; } # end if ($cat1 eq $cat_db_var) } # end for ($st=1; $st<=$jobvar_list; $st++) __END__ job types...<br> senior, exec...<br> exec, exec...<br> WHERE jobtype like '%exec%' and active='yes' AND jobstatus!='suspend' + ORDER BY dateadded DESC, jobtitle ASCstarting build lists<br>

Also, you can write your for loop in a more readable manner like this:

#OLD: for ( my $st = 0 ; $st <= @jobvar_list - 1 ; $st++ ) { for my $st ( 0 .. $#jobvar_list ) {

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039039]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-12-18 19:14 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (496 votes). Check out past polls.