Code:

#!/usr/bin/perl use strict; use warnings; #my $in_fileName = "/Users/me/test.txt"; #my $out_fileName = "/Users/me/test-out.txt"; my ($infi, $oufi, @data_array, $line, $ctr); my $txt1 = " Field:\t"; #open $infi, "<" . $in_fileName or die $!; #open $oufi, ">" . $out_fileName or die $!; while(<DATA>) { $line = $_; chomp($line); @data_array = split(/\t/, $line); $ctr = (@data_array) - 1; for ($ctr; $ctr >= 0; $ctr--) { print "$txt1,$data_array[$ctr],\t$ctr + 1, \t$.\n"; } print "Record: ", $line,"\n"; } #close $oufi; #close $infi; __DATA__ 1 2 3 4 5 6 7 8 9 10 11 12 13 1 +4 15 1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 11a 12 +a 13a 14a 15a
Outupt:
Field: ,15, 14 + 1, 1 Field: ,14, 13 + 1, 1 Field: ,13, 12 + 1, 1 Field: ,12, 11 + 1, 1 Field: ,11, 10 + 1, 1 Field: ,10, 9 + 1, 1 Field: ,9, 8 + 1, 1 Field: ,8, 7 + 1, 1 Field: ,7, 6 + 1, 1 Field: ,6, 5 + 1, 1 Field: ,5, 4 + 1, 1 Field: ,4, 3 + 1, 1 Field: ,3, 2 + 1, 1 Field: ,2, 1 + 1, 1 Field: ,1, 0 + 1, 1 Record: 1 2 3 4 5 6 7 8 9 10 11 12 + 13 14 15 Field: ,15a, 14 + 1, 2 Field: ,14a, 13 + 1, 2 Field: ,13a, 12 + 1, 2 Field: ,12a, 11 + 1, 2 Field: ,11a, 10 + 1, 2 Field: ,10a, 9 + 1, 2 Field: ,9a, 8 + 1, 2 Field: ,8a, 7 + 1, 2 Field: ,7a, 6 + 1, 2 Field: ,6a, 5 + 1, 2 Field: ,5a, 4 + 1, 2 Field: ,4a, 3 + 1, 2 Field: ,3a, 2 + 1, 2 Field: ,2a, 1 + 1, 2 Field: ,1a, 0 + 1, 2 Record: 1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 1 +1a 12a 13a 14a 15a

Hope that is helpful...

...the majority is always wrong, and always the last to know about it...

Insanity: Doing the same thing over and over again and expecting different results...

A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is a facct


In reply to Re: Printing in a WHILE loop by wjw
in thread Printing in a WHILE loop by gaseous1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.