#! /usr/bin/env perl use strict; use warnings; use Data::Dumper; # only used for debugging # define the version number # see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod use version; our $VERSION = version->declare("v3.3.0"); # see https://perldoc.perl.org/Getopt/Long.html use Getopt::Long; # allow -vvn (ie, --verbose --verbose --dryrun) Getopt::Long::Configure ("bundling"); # simple display if --help is passed sub help { use File::Basename; print basename($0) . " $VERSION\n"; print <, with style='headername' included Options: --title - A header to be created using

--nohtml - Do NOT create blocks --css filename - Create tag in to include css file --outfile filename - The output file (default to STDOUT) --delimiter char - the delimiter for the file (default tab) --encapsulate char - an encapsulation character (default none) --version - display version and exit --help - This page END } # handle any command line parameters that may have been passed in my $version = 0; # just used to determine if we should display the version my $help = 0; # also if we want help my $file = ''; # input file my $outfile = ''; # output file my $encapsulate = ''; my $delimiter = "\t"; my $noHTML = 0; my $cssFile = ''; my $title = ''; my $h2 = ''; GetOptions ( 'title|t=s' => \$title, 'outfile|o=s' => \$outfile, 'encapsulate|e=s' => \$encapsulate, 'delimiter|d=s' => \$delimiter, 'css|c=s' => \$cssFile, 'nohtml|n' => \$noHTML, 'h2|2=s' => \$h2, 'help|h' => \$help, 'version|v' => \$version, ) or die "Error parsing command line\n"; if ( $help ) { &help() ; exit; } if ( $version ) { use File::Basename; print basename($0) . " $VERSION\n"; exit; } my $line = <>; chomp $line; $line =~ s/_/ /g; # change all underscores to spaces $line =~ s/\b(\w)/\U$1/g; # capitalize the first letter in each word my @headers = split( $delimiter, $line ); # put into array my @out; # now, make this the table header push @out, '' . join( '', @headers ) . ''; # now, we'll make it all lower case, and replace spaces with underscores, for css $line = lc $line; $line =~ s/ /_/g; @headers = split( $delimiter, $line ); # put back into array while ( $line = <> ) { chomp $line; my @fields = split( $delimiter, $line ); my $lineOut = ''; for ( my $i = 0; $i < @headers; $i++ ) { $lineOut .= "$fields[$i]"; } push @out, $lineOut; } # add the header line at the top print "\n\n" . ( $cssFile ? "\n" : '' ) . "\n" . ( $title ? "

$title

\n" : '' ) . ( $h2 ? "

$h2

\n" : '' ) unless $noHTML; print "\n" . join( "\n", @out) . "\n
\n"; print "\n\n" unless $noHTML; 1;