Click here to get back home

Perl regex to remove c-comments, taking into account string literals

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Perl regex to remove c-comments, taking into account string literals Saeed 07-08-2004
Get Chitika Premium
Posted by Saeed on July 8, 2004, 9:51 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Lukas Mai on July 10, 2004, 10:12 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Similar ThreadsPosted
Regex trick, how to remove one quoted content from a string? November 9, 2004, 6:30 pm
Taking a string from body text and putting into a variable June 18, 2005, 8:25 pm
Install perl 5.8.3 and DBI, DBD::Oracle packages in my local account July 28, 2004, 4:46 pm
Solaris taking over Perl ownership November 5, 2004, 1:25 pm
Using regex to remove "redundant" tags October 26, 2005, 6:02 pm
Remove whitespace in tags using regex April 14, 2006, 10:04 pm
Regex to remove non printable characters December 21, 2007, 9:54 pm
Best way to remove last word from a string August 3, 2004, 11:33 pm
FAQ 9.4 How do I remove HTML from a string? March 23, 2005, 6:03 pm
how do I remove comma in a string May 15, 2005, 11:55 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap