Description: |
update: I've altered this module in various ways to make it meet my needs better. The latest version is here
Reading this thread reminded me that often I don't want
a particularly fancy table to display my lists of info, I just
want the same functionality you get in a word-processor with the
tab key. So I wrote this to provide just that functionality in an
intuitive way. You kick it off with the start_tabs(100,250,400,450)
function, for which you specify as many tab stops as you like, in
pixels. Then you put in your text, with a t at each
point you want a tab. The tabs wrap round, so that you go back to
zero after you've used up all your tab stops, but if you want to wrap
before, use r. Finally at the end end_tabs
shuts everything down. It's important to use this function because
the whole thing is translated into tables, and this is the function
that provides the </table> tag. The only difference
between this and the kind of tabbing you do in your word processor
is that, because it's done with tables, your text wraps between tabs -
which I think is an advantage.
Here's an example gobbet (you can
see the output from this
here:
#!/usr/bin/perl -w
use strict;
# path to my module library:
use lib '/home/htdocs/hosted/thinweb/lib/';
use CGI qw(:standard);
use CGI::tab;
my %data = (
foo => ['bimble','bumble','wimble'],
bar => ['nimble','numble','rumble'],
baz => ['zimble','zumble','gomble'],
);
print
header,
start_html,
h1('CGI::tab demo'),
hr,
h2('print out text from a hash:'),
start_tabs(150,300);
for my $key (keys %data) {
print $_,t for @{ $data{$key} };
}
print
end_tabs,
hr,
h2('arbitrary text to show wrapping capability:'),
start_tabs(100,250,350,400,450),
'hello',t,'everyone',t,'are',r,
t,t,t,t,t,'we',t,
'having',t,t,'fun',t,'yet?',
end_tabs,
end_html;
There's no rocket science here, but I find it a useful labour saver
in a situation that often comes up. I'd value your comments on how
to improve it, particularly from the point of view of making it efficient
as a module. |