Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
My java is a little rusty, but IIRC a method always has an optional access modifier at the start, then the return type, and then the method name (followed by the parameters). A one liner that might help is (very ugly):
grep { print scalar (@params = /^\s*(?:(?:public|private|protected)\s+ +)?\w+\s+\w+\s*\(([^,]+)(\,[^,]+)*\)/g);} <>;
If you save the above code as test.pl, then running
perl test.pl FILENAME
will give you the number of parameters for each method. The diamond operator will automatically fetch the contents of whatever file you pass to the script at the command line (or STDIN, if no file supplied). The above code, made easier to read:
grep { print scalar # print the number of items matched (@params = /^ # any whitespace at start of line \s* #optional access modifier (?:(?:public|private|protected)\s+) # return type and method name \w+\s+\w+\s* \( # params separated by commas ([^,]+)(\,[^,]+)* \) # don't really need m or s # since only one line is read at a time, # but I find it a good habit to always # use them /gxms); } <>; # read from keyboard or the file(s) provided on command line
I second izut's suggestion: read the perldocs.

In reply to Re: getting count of method params by unobe
in thread getting count of method params by neeha

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 studying the Monastery: (4)
As of 2024-04-18 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found