Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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
seventhdoesnotgetenoughsleepThis is some text that describes
seventhgetsomesleepThis is some describing text
seventhgethomesafeThis is some description
seventhwhyiraqThis 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

In reply to Re: Newbie question, advice appreciated by injunjoel
in thread Newbie question, advice appreciated by Seventh

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-23 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found