I think you need to get acquainted with "use strict". It might lead you to prefer using fewer variables overall, which would be a good thing. As for the logic in the OP, I'm puzzled. You say the ordering of input lines could be arbitrary, yet you have conditions based on the input line number. Apart from that, the "unless" block at the end is doing something that has no effect on the output: you change the value of $v2 and then don't use the modified value at all.
Here's a variant similar to the first reply, but with less typing:
use strict;
my @outputs;
while (<DATA>) {
my @fields = split;
push @fields, '' if ( @fields == 3 );
for my $i ( 0..$#fields ) {
$outputs[$i] .= $fields[$i] . '|';
}
}
chop @outputs; # remove final '|';
print "$_\n" for ( @outputs );
__DATA__
ID1 > 66
ID2 between 6 10
ID3 < 7
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.