+ my $max_array = scalar @{$array};
+ my $apjm1 = $opt->{array_per_job} - 1;
+ if ($opt->{array_per_job} > 1) {
+ # we will use subshells if there are more than one array
+ # items per job
+ @subshell = ('(',')');
+ $script .= <<EOF;
+for i in \$(seq 1 $opt->{array_per_job}); do
+# in some cases, the jobs aren't going to come out evenly. Handle that.
+JOBNUM=\$(( \${PBS_ARRAYID:=1} * $opt->{array_per_job} + \$i - $opt->{array_per_job} ))
+if [ \$JOBNUM -le $max_array ]; then
+OPT=\$(sed -n -e "\$JOBNUM p"<<'_HERE_DOC_END_'
+EOF
+ } else {
+ $script .= <<EOF;
+OPT=\$(sed -n -e "\${PBS_ARRAYID:=1} p"<<'_HERE_DOC_END_'
+EOF
+ }