Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039039]
help
Chatterbox?
[Discipulus]: have you been fired?!?
[LanX]: remote rules, I've been offered jobs in the US with the promise to stay outside
[MidLifeXis]: Nope. Just looking around, as there are multiple culture and business changes in the area I am in.
[MidLifeXis]: not yet, anyway. Who knows. Just do my best and whatever happens happens.
[LanX]: should be even easier for you
[Discipulus]: oh well we cant afford two monks fired in a day!
[LanX]: any news from tye ' s search?
[MidLifeXis]: Ugh - who else?
[Discipulus]: so the right term is 'gired'
[Discipulus]: look at ot by karl

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2017-03-23 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (286 votes). Check out past polls.