Article 9436 of comp.lang.perl: Xref: feenix.metronet.com comp.lang.perl:9436 Newsgroups: comp.lang.perl Path: feenix.metronet.com!news.utdallas.edu!corpgate!bnrgate!bnr.co.uk!uknet!pipex!uunet!psinntp!shellgate!shell!rjohnson From: rjohnson@conus.brc.shell.com (Roy Johnson) Subject: Re: Finding C comments In-Reply-To: merlyn@ora.com's message of 04 Jan 1994 17:24:58 GMT Message-ID: Sender: usenet@shellgate.shell.com (USENET News System) Organization: Houston, TX References: <2ga81r$93e@vixen.cso.uiuc.edu> <1994Jan4.104755.149466@embl-heidelberg.de> Date: Tue, 4 Jan 1994 21:50:05 GMT Lines: 26 merlyn@ora.com (Randal L. Schwartz) writes: > The right way to toss comments is to pull the string apart a little > a time. In Perl, it'd be something like this: > $_ = "your string here"; > $left = ""; # temp > while (//\*/) { # open comment? > $left .= $`; > $_ = $'; > die "Unterminated comment" unless /\*\//; > $_ = $'; > } > $_ = "$left$_"; # put parsed back into $_ And the wrong way, but one that works (credit Mark Biggar): s#/\*/*([^*/]*\*)+/##g; I thought this was in the FAQ, but I don't see it. I hope it will be in the next. -- -------- Roy Johnson ---- rjohnson@shell.com ---- Speaking for myself -------- "When the only tool you have is Perl, the whole | "Hooray for snakes!" world begins to look like your oyster." -- Me | -- The Simpsons (29 Apr 93) ------- "We _love_ being politically Koreshed" -- Steve Taylor, "Smug" -------