the code below is untested. mostly, i'm using it for illustration of the type of code you should be writing. use strict, warnings, and CGI. localize your typeglobs. test the return status of open and close. use split when it makes sense. take advantage of select to make printing easier.

#!/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*


In reply to Re: parsing out alias string better in perl to .htm by particle
in thread parsing out alias string better in perl to .htm by nanohurtz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.