Show us the code you tried. For that desired output, the modifications to the code I posted are not that complicated, especially with the suggestions that I already made. What I already said about collecting values from MYFILE will still work. Here are some additional hints to create the output you want:
-
For each line from NEWF, you need to check the index in column 5 and the A/B label in the last column. You get your hands on each of those with something like this:
my @fields = ( split /\s+/ ); # need to hold on to all field
+s for later
my( $index, $label ) = @fields[4, -1]; # this is an array slice
-
Now that you know the index and the label for a line, you use them to find the proper value from one of the arrays you created while reading from MYFILE (e.g., @a_vals or @b_vals if you followed my example). As I mentioned, before, you can use if/else to do that but a nicer way is with given/when (as long as your Perl is 5.10.0 or newer). Here's a suggestion but note that it will not work as written here. $x and $y are not declared. You need to replace them with the correct value from @a_vals or @b_vals (HINT: use $index from above).
use 5.010;
given( $label ) {
when ( 'A' ) { $fields[ -2 ] = $x; }
when ( 'B' ) { $fields[ -2 ] = $y; }
default { say "OOPS! bad label"; }
}
-
Now you can print the result:
say join "\t", @fields; # separates fields with TAB
That's all there is to it. Give it another go and post back with your code if you need more help.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|