• # Perl ftw

    Posté par (courriel, site web personnel) . En réponse au message Convertir les commentaires c++ en c. Évalué à 4.

    Bon, ça va poser problème si tu as un truc genre « char plop[] = "foo//bar"; » mais sinon ça a l'air de marcher :
    my $incomment;
    while (<>) {
     chomp;
     if (not m|^\s*//| and $incomment) {
     s|^| */$/|;
     undef $incomment;
     }
     if (m|//| and not $incomment++) {
     s|//|/\*|;
     s|$|$/|;
     next;
     }
     if ($incomment and m|^\s*//|) {
     s|(\s*)//|1ドル|;
     next;
     }
     if (not $incomment and not m|//|) {
     s|$|$/|;
     }
    } continue {
     print;
    }

    pertinent adj. Approprié : qui se rapporte exactement à ce dont il est question.