in reply to Re: print to output problem
in thread print to output problem

thanks for the effort Roy but still only prints the last $val?

Replies are listed 'Best First'.
Re^3: print to output problem
by Roy Johnson (Monsignor) on Jul 08, 2004 at 13:31 UTC
    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.