neeha has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: reading a java program
by Praveen (Friar) on Mar 14, 2006 at 05:36 UTC
    Try This
    undef $/; open(FIN,"$file_name"); $line =<FIN>; $line =~ s#public void(.*?)\);#/*$&*/#gs; print $line;
      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);
Re: reading a java program
by zer (Deacon) on Mar 14, 2006 at 04:51 UTC
    can you provide some source code or a more detailed description of what you are doing?
      I hope this is more readable.
      Hi Experts,
      My perl script reads every line in the java program. But i have a problem. If it is something like
      public void method1(String str1);
      It is ok.. it reads the whole line in one shot. But if i have something like
      public void method1(String str1, String str2);
      Then it reads this sentence as two lines. My requirement is i need to comment this line using java comments . Using my script now it happpens as
      /*public void method1(String str1,*/ String str2);
      Here the second line also has to be commented. Is there any way by which i can solve this problem????????????
      1)What i am doing is reading the file
      2)iterating through each line.
      3)check if the line starts with public
      4)if so then comment that line
      Zer, I hope u understood now.