Greetings all,
One other suggestion is to use
HTML::Template, if you have access to CPAN that is.
Im not sure how you want to handle the lines but here is a quick mockup that may or may not work for your purposes.
#!/usr/bin/perl -w
use strict;
use HTML::Template;
my $output_template = qq*
<table border="0" width="100%" cellspacing="1" bgcolor="#000000">
<tr bgcolor="#cccccc">
<td>Function Name:</td><td>Description</td>
</tr>
<TMPL_LOOP NAME="functions">
<tr bgcolor="#ffffff">
<td valign="top"><TMPL_VAR NAME="name"></td><td valign="top"><
+TMPL_VAR NAME="desc"></td>
</tr>
</TMPL_LOOP>
</table>
*;
my @output = do{
local @_;
#you will need to replace the DATA handle with
#one to your file of interest.
my $string = do{
local undef $/;
<DATA>
};
while($string =~ /\s?STANDARD\s+(.*?)\nfunction\s(\S+)\n?/mg){
push @_, {name=>$2, desc=>$1};
}
@_;
};
my $tmplt = HTML::Template->new(scalarref=>\$output_template,die_on_ba
+d_params=>0);
$tmplt->param({functions=>\@output});
print $tmplt->output();
exit;
__DATA__
blah
blah
blahblah blah
blah
blah
blah
blahblah blah
blah
# STANDARD This is some text that describes
function seventhdoesnotgetenoughsleep
# STANDARD This is some describing text
function seventhgetsomesleep
blah
blah
blahblah blah
blah
# STANDARD This is some description
function seventhgethomesafe
blah
blah
blahblah blah
blah
# STANDARD This is some text ...nuff said
function seventhwhyiraq
blah
blah
blahblah blah
blah
the output is
Function Name: | Description |
seventhdoesnotgetenoughsleep | This is some text that describes |
seventhgetsomesleep | This is some describing text |
seventhgethomesafe | This is some description |
seventhwhyiraq | This is some text ...nuff said |
Now in your code you will need to change the
<DATA> part to read in your file and as
dragonchild illustrated, TEST IF OPEN WORKED! Sorry for the caps but its a necessary step. Also you will need to open another handle (
and check if it opened) to your output file for writing. Is that what you were thinking?
I hope that helps
Update(s)!
This approach assumes that the file size is not enormous since it reads the entire file into $string. If the files are rather large you probably want to go with a line by line approach.
I updated the @output do block code to match across newlines.
Removed obsolete code from do block my @data = split /\#/, $string;
.
-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.