++jwkrahn and ++bichonfrise74.
Two other errors are lurking in the code.
- You are overwriting the run file on each loop. You probably just need to move the open to just before the loop.
- You are looping over for ($i=0;$i<=$#steps;$i++), ( which is better written as foreach my $i ( 0 .. $#steps ) ), but inside the loop you refer to $steps[$i-1]. On the first loop through, $i is 0, so $i-1 is -1, and $steps[-1] will give you the *last* element in the array. If that is what you meant to do, then fine. If not, then perhaps you need to start the loop index at 1 instead of 0?
Working, tested code:
#!/usr/bin/perl
use strict;
use warnings;
my @steps = ( 'ele1.0', 'ele0.5' );
die if @steps < 2;
open my $MIN_RUN, '>', 'run'
or die "Cannot open 'run': $!";
my $last_step = $steps[0];
for my $step ( @steps[1..$#steps] ) {
print $MIN_RUN "/opt/sander -i $step.min -p ../$step.prmtop -o $st
+ep$step.e &\n";
print $MIN_RUN "/opt/sander -i $step.min -p ../../$last_step/$last
+_step.prmtop -o $step$last_step.e &\n";
$last_step = $step;
}
close $MIN_RUN or warn;
Output:
/opt/sander -i ele0.5.min -p ../ele0.5.prmtop -o ele0.5ele0.5.e &
/opt/sander -i ele0.5.min -p ../../ele1.0/ele1.0.prmtop -o ele0.5e
+le1.0.e &
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.