Hi monks im trying to complete my homework but i got stuck in between...This is my 2 nd week of learning perl and im not very good wiht regex...Im trying to extract some text from a C file and im writing to a .doc file..

The C file format is Function: stdio.h Input: None Output : Performs Standard input output operations <Some Code here> Function: math.h Input: Mathematical operators Ouput: Performs mathematical operations <Some Code here>

The output in the .doc file should be like this

Function: stdio.h Output: Performs Standard input output operations Input: None Function: math.h Output: Performs mathematical operations Input: Mathematical operators

Im have written a snippet to open MS Word and read the .c file and extract the function name and the snippet is below:-

use warnings; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Const 'Microsoft Word'; use Cwd; use File::Find; //MS Word Opening my $word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add; my $selection = $word->Selection; my @scriptfiles; my $text; my @array; our $file; @scriptfiles=glob('*.c'); foreach $file (glob('*.c')) { open(my $fh, $file) or die("Unable to open '$file': $!"); while (my $line = <$fh>) { if ($line =~ /Function:\s*(.+)/ ) { $selection -> TypeText($line); } } }

The issue is how to extract the Input and output from the .c file. Im extracting Function name first then i have to extract Output and then input..im currently reading the .c file ($line = <$fh>) and searching for the function name how to do the same for Output and Input..pls teach me thanks...


In reply to Understanding Regex by jack_64

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.