Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: getting count of method params

by unobe (Scribe)
on Mar 14, 2006 at 23:27 UTC ( #536730=note: print w/replies, xml ) Need Help??

in reply to getting count of method params

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, then running
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://536730]
[pryrt]: The mismatched ones have a Jan 23 2017 Last-Modified header -- I wonder if they rezipped them and forgot to update the sha1
[stevieb]: RT ticket for the csum mismatch of various versions of Strawberry Perl

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2017-03-29 21:10 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (353 votes). Check out past polls.