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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |