in reply to reading a java program

Try This
undef $/; open(FIN,"$file_name"); $line =<FIN>; $line =~ s#public void(.*?)\);#/*$&*/#gs; print $line;

Replies are listed 'Best First'.
Re^2: reading a java program
by neeha (Novice) on Mar 14, 2006 at 07:00 UTC
    This program works like magic.. Thank u very much. But I have some conditions to check.
    The description what i had given was just an overview of the script.
    I have a list of methods. I need to comment the
    public void met1(String str1, String str2)
    What i do is get all the methods from the list and comment only those method names.
    So if "met1" is there in the list then only it shoud be commented
    so for that only i was iterating through each line to see if that method in the list exist in the program.
    if that method is there in that line then comment that line.
    ur script works fine when i dont iterate through each line .
    is there any way by which i can achieve the requirement.
      Have a list like this @method_ary =('met1','set1','wat1'); Then change this line to
      $line =~ s#public void $_(.*?)\);#/*$&*/#gs,for(@method_ary);
        Thank u very much Praveen.
        I am very new to writing perl scripts.I am basically a Java Programmer. It is amazing that u can do so much in just one line of perl script. I have one more clarification.
        public void method1(String str1,String str2)
        I am reading this java program using perl
        Can i know how many parameters are there in this "method1" Right now i am doing lot of manipulations like substring and using split to get the no of parameters. is there any short way or correct way of doing it.