in reply to parsing out alias string better in perl to .htm
#!/usr/bin/perl use strict; ## keeps you honest, makes you a better programmer use warnings; ## this too... use diagnostics; ## for explanations of error an warning messages require 5.006; ## use the html generation methods in the infamous CGI module use CGI qw/:standard/; my( $infile, $outfile ) = ( 'prevplanin.txt', 'prevplanout.htm' ); my ($varalias, $varsource, $vartarget); ## indent your code properly { ## localize your typeglobs so you don't pollute the namespace. ## this is done by creating them with [local] inside a block local( *IN, *OUT ); ## always test for failures on file open open( IN, "<", $infile ) or die "ERROR: can't open $infile: $!" open( OUT, ">", $outfile ) or die "ERROR: can't open $outfile: $!"; ## select the filehandle, so you don't have to specify it when you p +rint select OUT; ## specify autoflush mode, so print output is line buffered $|++; # print your html header print start_html( -title => 'PLAN VERIFICATION', -bgcolor => "#FFFFFF", -text => "#000000", ); ## set your input record seperator. here i chose newline followed by + "alias " ## this way you can support multi-line input strings $/ = "\nalias "; ## for each record while( <IN> ) { ## split the space-seperated fields of your record ## take a slice of the array [split] returns my( $alias, $source, $target ) = (split)[0,4,6]; { ## use CGI's html generation to create your table print table( { -width="37%", -border="0", -cellspacing="1", -cellpadding => + "0" }, [ Tr( { -bgcolor => "#0099CC", }, td( { -colspan => "2" }, 'alias retrieved' ) ), Tr( td( { -width => "11%", -bgcolor => "#CCCCCC" }, b( 'alias' ), ), td( { -width => "89%", -bgcolor => "#FFCC99" }, $alias, ) ), ## repeat for $source and $target ## ... ## you don't need $i, you can use $. instead (current record + number) ] ); } print OUT "</body></html>" } ## finish your page print end_html(); ## remember to check return status of close, too close( IN ) or warn "Warning: can't close file: $!"; close( OUT ) or warn "Warning: can't close file: $!"; ## we're done with *OUT, select a valid filehandle select STDOUT; }
~Particle *accelerates*
|
|---|