daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Jun 30th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. open STDIN, '<input.txt';
  2. open STDOUT, '>output.txt';
  3. my $in_a_comment = 0;
  4. while (<>) {
  5.     my $s = $_;
  6.     if ($s =~ m[\/\*]) {
  7.         my $index1 = index ($s, '//');
  8.         my $index2 = index ($s, '/*');
  9.         if (($index1 > $index2) || ($index1== -1) && (!$in_a_comment)) {
  10.             $in_a_comment = 1;
  11.             print substr($s,0, $index2 + 2);
  12.             $s = substr($s, $index2 + 2);
  13.         }
  14.     }
  15.     my $index3 = index ($s, '*/');
  16.     if ($in_a_comment) {
  17.         if ($index3 == -1) {
  18.             print $s;
  19.             next;
  20.         }
  21.         else {
  22.             if ($index3 != -1) {
  23.                 print substr($s,0,index($s, '*/') + 2);
  24.                 $in_a_comment = 0;
  25.                 $s = substr($s, index($s, '*/') + 2);
  26.             }
  27.         }
  28.     }
  29.     if (((my $i = index($s, '//')) != -1 ) && (!$in_a_comment)) {
  30.         my $tmp = substr($s, 0, $i);
  31.         $s = substr($s, $i);
  32.         $s =~s[\*\/][\* \/]g;
  33.         $s =~s[\/\/][\/\*];  
  34.         $s =~s[\n][\*\/\n];
  35.         $s .= "*/" if (index($s, "\n") == -1);
  36.         $s = $tmp . $s;
  37.     }
  38.     print $s;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top