Re: Analize Java source file with perl?



On 10/26/06, bou, hou (GE Money, consultant) <hou.bou@xxxxxx> wrote:
hello, all
I want to get the Class name of .java file with perl ,

I want to get like this
>perl ClassChecker.pl AAA.java
>ClassA
>ClassB

Quick and dirty:

$ perl -n -e 'print "$1\n" if /class\s+(\w+)/' AAA.java
ClassA
ClassB

This does not know anything about Java syntax and just looks for a
word after 'class' and some space. If it is in comments or you have
something like

public class
Foo {
}

it won't understand it.

More robust solutions are feasible. For example, after improving the
recent CPAN module Parse::Java, you can do a lot better. To quote
Randal, "Learn or hire".
.



Relevant Pages

  • Re: Analize Java source file with perl?
    ... I want to get the Class name of .java file with perl, ... public class ClassA { ... class ClassB { ...
    (perl.beginners)
  • Re: Analize Java source file with perl?
    ... I want to get the Class name of .java file with perl, ... public class ClassA { ... parse it looking for class declarations. ...
    (perl.beginners)
  • Analize Java source file with perl?
    ... I want to get the Class name of .java file with perl, ... public class ClassA { ... class ClassB { ...
    (perl.beginners)
  • Re: Commenting Java
    ... Unfortunately I'm unfamiliar with Perl. ... Do u think its a good idea to start learning Perl just to add some ... I'd like to add a copyright on top of every java file ...
    (comp.lang.java.help)
  • include_once() in perl
    ... when using Perl, i.e. ... if ClassA already include ClassB ... is it safe to use in this way? ... or sth like that exist in Perl? ...
    (perl.beginners)