Hello Monks
i have a problem in printing arrays ( containing elements) in fixed column width.
* i have one array containing header's or column names
* The next array containing multiple rows i.e. data
* i want to display in report format with each header with fixed width and corresponding data should come below header..
pls see below data to get an idea
__DATA__
TABNAME 06100 01010 06000 00110A
# The above is header which is present in @header
!W31801!-->!919!-->!90200809!-->!840!-->!MO!
!W31801!-->!919!-->!902008!-->!74!-->!MO!
#The above are the data present in @data array
# iam doing below ...
my $disp = sprintf("-%10s\n",join("\t",@header));
print $disp; # i printed header
foreach my $line (@data){
my @arr = split(/-->/,$line);
my $disp = sprintf("-%10s\n",join("\t",@arr));
print $disp;
}
# From above iam cant achieve what i need, the resultant data is out o
+f format...
# All i need is , no matter whats the size of data or header, i want t
+o print each column with width of 10 characters .
__DATA__
-TABNAME 06100 01010 06000 00110A
-!W31801! !919! !90200809! !840! !MO!
-!W31801! !919! !902008! !74! !MO!
# As you can see output , headers are not alighned properly, i need he
+aders and corresponding data to be left alighned and in same column..
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.