Re: tabular format of data
by ww (Archbishop) on Feb 18, 2012 at 00:52 UTC
|
Text::AsciiTable -- suggested by AM -- will allow you to have Perl print a plain-text, ink-on-dead-trees (or phosphors on a CRT, for another archaic technology) that will very closely match -- in appearance -- what you showed us.
But we could use some help from you, to help you.
How are you using "tabular?" In other words, do you mean an HTML table, an ASCII art representation such as you showed, or simply a <TAB> separated file (aka "tab separated file, or "TSV"), which can be printed to the aforesaid 'dead-trees' with sufficient spacing to make the columns distinct from one another?
Your followup node (it could have been edited into the original with an appropriate note marking the new content as an UPDATE) seems to me to mean that you have A:B in one array, and C:D in another. If accurate, that's merely going to require that you deal with two arrays, whereas, if "A:B" is a single value, then you can easily put as many such values as you need into a single array.
OTOH, if your "A:B" is a key:value pair (for example, if "A" is on the order of a family name, and "B" is like a given name), then consider using a hash as the intermediate format for your data.
| [reply] |
|
|
two arrays i have used to store the valus
arrr1 will contact column1
arry2 will contain column2
and I wanted to repsnt in a tabular form , it might be either in HTML tabular form with border or formatted with hypens
| [reply] |
|
|
A.txt:- A:B C:D code: # it has column1 values of txt file @a1=`cut -d":" -f1 < A.txt; # it has column2 values of txt file @a2=`cut -d":" -f2 < A.txt; I wanted to reprent the values in tabular form
| [reply] |
|
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
Re: tabular format of data
by JavaFan (Canon) on Feb 18, 2012 at 00:45 UTC
|
my @data = map {chomp; [split /:/]} <DATA>;
my $width = length $data[0][0]; # Assume they're all the same length
+.
my $Width = @{$data[0]};
my $divider = "-" x (($width + 1) * $Width);
my $topline = $divider x 2; chop $topline;
say $topline;
foreach my $line (@data) {
print "$_|" for @$line;
say "\n$divider";
}
__DATA__
A:B
C:D
This prints:
-------
A|B|
----
C|D|
----
| [reply] [d/l] [select] |
|
|
Actually, I have stored column1 values in Arr1 and column two values in Arr2.
Is it possible to represetn them in tabular format?
| [reply] |
|
|
Sure. Replace my first line with:
my @data;
foreach (my $i = 0; $i < @Arr1 && $i < @Arr2; $i++) {
$data[$i] = [$Arr1[$i], $Arr2[$i]];
}
| [reply] [d/l] |
A reply falls below the community's threshold of quality. You may see it by logging in.
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
|
|
| [reply] |
|
|
|
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
|
|
also i have tried the above code..
its printing like
A
|B
|C
|D
| [reply] |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Re: tabular format of data
by Anonymous Monk on Feb 18, 2012 at 00:37 UTC
|
| [reply] |
|
|
:)
how can i use in a perl script?
| [reply] |
|
|
| [reply] |
Re: tabular format of data
by toolic (Bishop) on Feb 18, 2012 at 02:05 UTC
|
| [reply] |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Re: tabular format of data
by davies (Monsignor) on Feb 20, 2012 at 10:38 UTC
|
Look at the root node of this thread - that's the one I'm replying to. It has been edited by davido to include the code tags that you should have put in. If you load that node, you will be able to see both the node as it appears to the rest of us and the actual text - complete with the janitor added code tags - that generate the output. You are used to seeing the box with the markup, as that is what you use to post. Above that box are instructions for the use of code and paragraph tags. Compare the text in the entry box with the instructions above. Then go through all your posts and add code tags as davido did to your first post.
Regards,
John Davies
| [reply] |
|
|
Hi Team,
Could you pls help me to wrtie a code where I can present the output in HTML tabular format with border.
For ex. with 2-row and 2-column
Please help!!!
| [reply] |
Re: tabular format of data
by tchrist (Pilgrim) on Feb 18, 2012 at 02:31 UTC
|
| [reply] |
|
|
Is that the 'christ' part of your nick getting some play, Tom? :)
I think that sending the OP off to learn 'tbl' and all that other related stuff would drive him bats. He's having a hard enough time understanding how to use code tags, for Ghu's sake. I suspect 'printf' would be a bit more his speed - if he ever settles down and actually pays attention to the people's replies to his questions.
Deepak - please start paying attention to the replies that people have given. There's plenty of information here, all you would ever need to do what you've asked about. And PLEASE start using code tags: when you write your post, surround the code part - the part that you want to show in its original format - with a <c> tag above it and a </c> tag below it. Everyone, including you, will be happier if you do.
--
I hate storms, but calms undermine my spirits.
-- Bernard Moitessier, "The Long Way"
| [reply] |
|
|
Is that the ‘christ’ part of your nick getting some play, Tom? :)
Hey, it’s when I start signing with †☧ᶥſt that you’ll really have to worry. 😇
I just couldn’t help myself. His mendicant petitions were so subclubious that ... well ... er ... how ’bout I thought something simple might work better? Surely they couldn’t be worse!
Yeah yeah, okay. You were supposed to laugh.
But it’s true that I personally have always found tbl a lot easier than HTML tables, which are kinda nightmarish. But what do you expect? So is all markup language. I could sing you a slow song of DocBook — call it a dirge — whose lamentations would strike dumb your tongue and rip your heart asunder, and you would claw out your eyes to save them from every having to look at it again.
And it’s coming soon to a bookstore near you. 🙆
++tol
| [reply] |
|
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
A reply falls below the community's threshold of quality. You may see it by logging in. |
Re: tabular format of data
by deepak_4682us (Initiate) on Feb 18, 2012 at 00:35 UTC
|
Also, i have stored tha values in two arrays
how can i represnt them in a tabular form | [reply] |