If you don't want the whole file to be slurped in at once
you could, since lines of code are seperated by semi-colons in C, just use a semi-colon as an end-of-line indicator: local $/ = ';';.
Updated code that should not match ifs and such:
#!perl -w use strict; $/ = ';'; my ($header, $type, $arguments); for my $data (<DATA>) { $data =~ s/(((?:static\s+)?\w+)\s+(\w+)\s*\(([^)]*)\)\s*\{)/($3 eq 'if' or $3 eq 'do' or $3 eq 'while' o +r $3 eq 'for') ? +$1 : "\/* Function: $3()\n" . " Input:\n" . do { $header = $1; $type = $2; $arguments = $4 . ','; '' +} . (join "\n", map { sprintf " %-8s %8 +s : ", split } $arguments =~ m|\s*(\w+\**\s+\**\w+)\s*,|g) +. "\n\n" . " Output:\n" . (sprintf " %-8s : \n", +$type) . "\n Author :\n Date :\ +n*\/" . "\n\n$header"/ge; print $data; } __DATA__ int function(int a, char *b) { ... return 0; }
(only if it is not HW)
Hope this helped (and I hope your question was not HW, but for work, documentation or something similar as I suppose it to be).

In reply to Re: regex 2 match C function by CombatSquirrel
in thread regex 2 match C function by jai

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.