in reply to avoiding a particular character or set of characters

the easiest solution I see is filtering out those comments.
while ( $javacode =~ s{ (/\*\* .*? \*/) }{ <!--REPLACED_COMMENT--> }xm +s ){ push @comments, $1; } my @lines = (); LINE: foreach my $line (split "\n", $javacode) { push @lines, $line; next LINE if $line =~ m { \A \s* // }xms; # change lines $lines[-1] =~ ... } $javacode = join "\n", @lines; my $comment_id = 0; $javacode =~ s{<!--REPLACED_COMMENT-->}{$comment[$comment_id++]}eg;
I'm sure there is a shorter version and I want to see that, saints :)

Replies are listed 'Best First'.
Re^2: avoiding a particular character or set of characters
by neeha (Novice) on Mar 27, 2006 at 15:20 UTC
    cant i have a solution like
    $str ="check this out";
    if this sentence has out do not replace it
    if($str =~ s#check this [^out]#check this one#){ }
    is there some way to achieve this
    one more thing i am not traversing line by line.
    the whole java file i am taking as a single line
    using undef $/;

      Hi neeha, you cannot use character class here, rather you have to use negative look head.

      change

      if($str =~ s#check this [^out]#check this one#){ }

      into

      $str ="$str ="check this out check this here";"; $str =~ s#check this ((?!out).)+#check this one#gs; print $str;

      Prasad

      my problem is
      /** * public void method1(); * is deprecated */ public void method1();
      in this case my code replaces to
      /** * replaced code */ public void method1();
      It dont want to replace anything in the comments
      and my code reads the entire java file as a single line.