view tabular2HTML.pl @ 0:a5814dd5a11a default tip

Uploaded
author ondovb
date Fri, 23 Sep 2011 17:06:15 -0400
parents
children
line wrap: on
line source


use strict;

my ($table, $input, $output, @spans) = @ARGV;

# positions that should have dark right borders
#
my %dark;

foreach my $span ( @spans )
{
	if ( $span > 1 )
	{
		# only initialize if there are any spans more than 1
		
		pop @spans;
		my $i;
		
		foreach my $span ( @spans )
		{
	    	$i += $span;
		    $dark{$i - 1} = 1;
		}
		
		last;
    }
}

open TABLE, ">>$table" or die $!;
open INPUT, "<$input" or die $!;

my $parity;

while ( my $line = <INPUT> )
{
	chomp $line;
	
	my @vals = split /\t/, $line;
	
	$parity = ( $parity eq 'odd' ? 'even' : 'odd' );
	
	print TABLE "<tr class='$parity'>";
	
    for( my $i = 0; $i < @vals; $i++ )
    {
		my $val = $vals[$i];
		my $class;
	
		if ( $dark{$i} )
		{
			$class = ' class="darkRight"';
		}
	
		$val =~ s/</&lt;/;
		$val =~ s/>/&gt;/;
	
		print TABLE "<td$class>$val</td>";
	}
	
	print TABLE "</tr>\n";
}

close INPUT;

print TABLE "</table></body></html>\n";

close TABLE;

`mv $table $output`;