Data-ShowTable
view release on metacpan or search on metacpan
usage "$PROG: bad HTML format element '%s'", $_;
}
push(@Dformats,@dformats); # allow multiple options
$Show_Mode = 'HTML';
} elsif (!index('-urls',$_)) {
# parse COL1=URL1,COL2=URL2,...
# or: COL1:URL1,COL2:URL2,...
my @urldefs = split(/[,|]/, $value); # get the different URLs
my $urldef;
foreach $urldef (@urldefs) {
my ($col, $url) = split(/[=:]/,$urldef,2);
if ($col ne '' && $url ne '') { # both defined?
$URLs{$col} = $url; # save the mapping
} elsif ($col ne '' || $url ne '') {
usage "$PROG: bad URL format element: '%s'", $urldef;
}
}
$Show_Mode = 'HTML'; # make sure
} elsif (!index('-attributes',$_)) {
$table_attributes .= ' '.$value; # build up the list
$Show_Mode = 'HTML';
} else {
usage "$PROG: Unknown option: $_";
}
} elsif (/^-/) {
usage "$PROG: Unknown option: $_";
} elsif (-f) { # does the file exist?
open(STDIN,"<$_") ||
die "$PROG: Can't open $_ for input: $!\n";
ShowData;
close(STDIN);
$nofile = 0;
} else {
err "File $_ does not exist.";
exit 1;
}
}
ShowData if $nofile;
exit;
# $type = guess_type $value
sub guess_type {
local $_ = shift;
&PlainText if $Show_Mode eq 'HTML'; # remove HTML effects if -html
# so they aren't part of the typing
s/^\s+//; s/\s+$//; # trim leading & trailing blanks
/^$/ && return 'null'; # null type
/^([01tf]|yes|no|on|off)$/i && return 'bool'; # 0, 1, yes, no, on, off, t, f
m=^\d{2,4}[-/.]\d{1,2}[-/.]\d{1,2}$= && return 'date'; # mm/dd/yy, yy/mm/dd, yyyy.mm.dd, yyyy-mm-dd
m=^\d{1,2}[-/.]\d{1,2}[-/.]\d{2,4}$= && return 'date'; # dd.mm.yyyy, d.m.yy, dd-mm-yy
/^\w{3,9} \d{1,2}, \d{4}/ && return 'date'; # mmmm dd, yyyy
/^\d{1,2}[- ]\w{3}[- ]\d{2,4}$/ && return 'date'; # dd mmm yyyy
/^\d\d:\d\d(:\d\d)?$/ && return 'time'; # hh:mm:ss
/^[-+]?\d+$/ && return 'int'; # +-nnnn
/^[-+]?[\d.]+(E[+-]?\d+)?$/ && return 'real'; # +-nnn.nnn(E+-nn)
/^[-+]?[\d.]\%$/ && return 'pct'; # nn%, nn.n%, -nn.nnn%
/^-?\(?\$[ \d,.]+\)?(?: *CR)?$/ && return 'money'; # $ nn,nnn.nn or ($ nnn,nnn.nn)
/^-?\(?[\d]+,[\d,]+(\.(\d\d)?)?\)?$/&& return 'money'; # nnn,nnn.nn or ( nnn,nnn.nn)
/^['"]|["']$/ && return 'string'; # "xxxx"
/^\w+$/ && return 'symbol';
/\n/ && return 'text';
return 'char';
}
# Do type conversion
sub new_type {
my @types = @_;
my $type1 = $types[0];
my $type2 = $types[1];
# trivial conversions
$type1 eq '' && return $type2;
$type2 eq '' && return $type1;
$type1 eq $type2 && return $type1;
# handle null types
$type1 eq 'null' && return $type2;
$type2 eq 'null' && return $type1;
# These types supercede others
grep(/text/i, @types) && return 'text';
grep(/string/i, @types) && return 'string';
grep(/char/i, @types) && return 'char';
# Now do finer-grain conversions
grep(/money/i, @types) && return 'money';
grep(/pct/i, @types) && return 'pct';
grep(/real/i, @types) && return 'real';
grep(/int/i, @types) && return 'int';
grep(/symbol/i, @types) && return 'symbol';
grep(/bool/i, @types) && return 'bool';
$type1; # huh?
}
sub ShowData {
@Data = ();
# reset titles if they are coming from the data stream
#@Titles = () if $Titles > 0;
@Types = ();
@Widths = ();
my ($titles, $data, $maxcols);
if ($InputType eq 'list') {
($titles, $data, $maxcols) = ReadListInput;
} else {
($titles, $data, $maxcols) = ReadTableInput;
}
my @titles = @$titles;
@Data = @$data;
# Make the fields selection
if (@Fields) {
# build a field index list
my ($f,$fx);
my %fields = ();
my @fields = (); # an index list
( run in 1.667 second using v1.01-cache-2.11-cpan-5735350b133 )