Even though your subject is printf, you ask a much larger question in regards to converting your data into columns going across rather than down. The easiest option by far (assuming you have the memory to do so) would be to create a new data structure in the form of a 2 dimensional array and then you can easily print it out using some nested for loops:

#!/usr/bin/perl -w use strict; use Data::Dumper; our @qqq=(1..100); sub print_col { my ($rows, $qref)=@_; my @cols=(); my $count=0; while($count<=$#$qref) { #This for loop creates the 2D array for (0..$rows-1) { push @{$cols[$_]}, $qref->[$count]; $count++; #This makes sure to stop when we run out of data last if $count > $#$qref; } } #Data::Dumper just in here for testing, love that module #print Dumper(\@cols); #This for loop prints it, notice I use the quoted array syntax + #which causes print to output the array with spaces in between + # each element. However, this is the perfect place to put #another for loop or a map statement and printf each element #with the correct width and other formatting you want. for (0..$#cols){ print "@{$cols[$_]}\n"; } } print_col(shift, \@qqq); ###################### ## Output $ ./testcols.pl 25 1 26 51 76 2 27 52 77 3 28 53 78 4 29 54 79 5 30 55 80 6 31 56 81 7 32 57 82 8 33 58 83 9 34 59 84 10 35 60 85 11 36 61 86 12 37 62 87 13 38 63 88 14 39 64 89 15 40 65 90 16 41 66 91 17 42 67 92 18 43 68 93 19 44 69 94 20 45 70 95 21 46 71 96 22 47 72 97 23 48 73 98 24 49 74 99 25 50 75 100

HTH


In reply to Re: how to use printf correctly... by pzbagel
in thread how to use printf correctly... by bioinformatics

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.