0

FILE CONTAINS FUNCTION DEFINITIONS AND FUNCTION DECLARATIONS

eErrorT ChainCtrlUpdateCameraRoute(ChainCtrlT* pChainCtrl, RouteListItemT* pNewRoute, RouteListItemT* pCurrRoute);

eErrorT ChainCtrlSetJpgSnapshotFile(ChainCtrlT* pChainCtrl, RouteListItemT* pRoute, char * dst_chain, char *jpg_file_path)
{

} 

MY CODE

use strict;
use warnings;
use vars qw(@temp $index $i);

open(my $FILE, "< a.c") or die $!;
my @arr = <$FILE>;
foreach(@arr){  
   if($_ =~ /^ \S+ \s+ \S+ \s* \( (.+?) \) /xsmg) {    # extracts function arguments
      my $arg = $1;
      my @arr = map /(\w+)$/, split /\W*?,\W*/, $arg;
      print @temp = map "$_\n", @arr;
     }
} 

GIVES OUTPUT

pChainCtrl
pNewRoute
pCurrRoute
pChainCtrl
pRoute
dst_chain
jpg_file_path

OUTPUT NEEDED

pChainCtrl
pRoute
dst_chain
jpg_file_path

I need to extract arguments only from function definition(ChainCtrlSetJpgSnapshotFile) and not declaration(ChainCtrlUpdateCameraRoute).

I need to look whether the line with (..) doesn't have ";" in the same line. but I am unable to get regex command for it

3
  • // is not a comment in Perl, use # for that. // is the "defined-or" operator. Commented Oct 4, 2013 at 13:07
  • it was just to explain the code..actual code is quite bigger than this.I just gave u a sample where I am stuck Commented Oct 4, 2013 at 13:20
  • Why don't you just add a semi-colon in a negative lookahead assertion? (?!\s*;) Commented Oct 4, 2013 at 13:25

1 Answer 1

2

Trying to understand what is the technical (lexical) difference, I see a ";" at the end of the definition, and no no ";" at the end of the declaration. In addition you have a { at the next line.

Utilizing these features (if they are consitent, fingers x'ed)

#ignore lines with ; (followed by optional spaces) at the end
print @temp = map "$_\n", @arr 
    unless $_ =~ /;\s*$/;

An option may be look for the { at the next line, and only print previous line, if you had a match, and this line start with a {. (to be left as an exercise...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.