in reply to print to output problem

Does this do what you want?
while (<FILE>) { undef $val; if (/^# input/) { ($etc) = (split)[1] } elsif (/^\s\s\d+/) { ($space, $Nd, $RES, $PDB, $val) = split } elsif /^\s.*$NUM17\b/) { $val = (split)[3] } elsif /^\s.*$NUM18\b/) { $va2 = (split)[3] } if (defined $val) { push(@outlines, $val); print $val; } }

We're not really tightening our belts, it just feels that way because we're getting fatter.

Replies are listed 'Best First'.
Re^2: print to output problem
by Anonymous Monk on Jul 08, 2004 at 10:30 UTC
    thanks for the effort Roy but still only prints the last $val?
      It looks like you need to store up your $NUM17 values in an array, and you also need to store up your RES-val pairs in a hash. Then, after you've read and stored the whole mess, go through the array and print the corresponding hash values. Like:
      my @requests = (); my %lookups = (); while (<FILE>) { if (/^# input/) { push @requests, (split)[1]; } elsif (/^\s\s\d+/) { my ($RES, $val) = (split)[2,4] $lookups{$RES} = $val; } } print join("\n", @lookups{@requests}), "\n";
      It's not clear to me what the $NUM17 and $NUM18 business is all about, or what $etc is for. What I've done is assume that $etc indicates which $RES to look for, to print the associated $val.

      We're not really tightening our belts, it just feels that way because we're getting fatter.