Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Help with a loop

by frozenwithjoy (Curate)
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 ) {

Comment on Re: Help with a loop
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039039]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2015-07-29 17:59 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (267 votes), past polls