File: demo_cols.pl

package info (click to toggle)
libtext-reform-perl 1.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 188 kB
  • ctags: 31
  • sloc: perl: 1,251; makefile: 39
file content (70 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/perl -w

use Text::Reform;

# Easy when data already in columns...

@name  = qw(Tom Dick Harry);
@score = qw( 88   54    99);
@time  = qw( 15   13    18);

print form
'-----------------------------',   
'Name             Score   Time',   
'-----------------------------',   
'[[[[[[[[[[[[[[   |||||   ||||',
\@name,          \@score,\@time;

print "\n"x2;

# Not so easy when data in rows...

@data = (
	{ name=>'Tom',   score=>88, time=>15 },
	{ name=>'Dick',  score=>54, time=>13 },
	{ name=>'Harry', score=>99, time=>18 },
);


# The ugly way...

print form
'-----------------------------',   
'Name             Score   Time',   
'-----------------------------',   
'[[[[[[[[[[[[[[   |||||   ||||',
[map $$_{name},  @data],
[map $$_{score}, @data],
[map $$_{time} , @data];

print "\n"x2;

# The nice way...

print form
'-----------------------------',   
'Name             Score   Time',   
'-----------------------------',   
'[[[[[[[[[[[[[[   |||||   ||||',
{ cols => [qw(name score time)],
  from => \@data
};


@data = (
	[ 15, 'Tom',   88 ],
	[ 13, 'Dick',  54 ],
	[ 18, 'Harry', 99 ],
);

print "\n"x2;


# Works for arrays too...

print form
'-----------------------------',
'Name             Score   Time',   
'-----------------------------',   
'[[[[[[[[[[[[[[   |||||   ||||',
{ cols=>[1,2,0], from=>\@data };