in reply to replace java code when not commented

This works on your test code.
#!/usr/bin/perl use strict; use warnings; while (<DATA>){ print /^public/?$_ = "/*".$_."*/":$_; } __DATA__ /** * public void method1(); * is deprecated */ public void method1();

Replies are listed 'Best First'.
Re^2: replace java code when not commented
by zer (Deacon) on Mar 28, 2006 at 05:51 UTC
    Heres an update. This allows for tabbing and private methods. I am not sure how many method types there are in java but this is the direction to go.
    use strict; use warnings; while (<DATA>){ print /^\s*(public)|^\s*(private)/?$_ = "/*".$_."*/\n":"$_\n"; } __DATA__ /** * public void method1(); * is deprecated */ public void method1(); rgrprivate void method2(); private void method3();

    Output:
    /**
    * public void method1();
    * is deprecated
    */
    /*public void method1();*/
         rgrprivate void method2();
    /*    private void method3();*/