On Thu, Nov 15, 2001 at 12:05:15AM -0500, Michel Lambert wrote: > As for an improvement on japhy's submission to handle "# define FOO 1", > what about this 80 character submission: > > perl -pe's/^\s*#\s*(?!\s|include|define|ifn?(def)?|else|elif|undef|endif).*/ > /m' your_file > > Japhy's original submission used /s, but I think he meant /m ... > > Also note that all of the given submissions fail on: > '#defined this variable here for efficiency reasons'. Do they need to use > \b? > > perl -pe > 's/^\s*#\s*(?!\s|include|define|ifn?(def)?|else|elif|undef|endif)\b.*//m' > your_file > > If this slightly-wronged-ness is okay, how far can we take it? :) Or is > correctness paramount?
Correctness is important. Can't drop anything that's a CPP command. I'm currently using this for #1. perl -ne '/^\s*#(?!\s*(include|define|if(n?def)?|el(se|if)|undef|endif))/||print' your_file which is one character shorter, and I think it's correct. > You have one aspect of your problem which might confuse perl-golfers tho. > Can you use modules in your real-work task, even though they are disallowed > by the rules of perlgolf? No, this is going literally into perl.c of the perl core. All you have available is what's in the core. > Of course, there may be reasons where you can't use files, in which case > nevermind. Or, you could lobby for this wonderfully named, designed, > documented, and test-including Strip.pm to be added to the core. :) That might not be such a bad idea. OTOH nobody really gives a shit about -P anymore. I'm sort of doing this as a large-scale exercise in anal-retentiveness. Don't think of it as gaining VMS, think of it as losing sed. ;) -- Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/ Perl6 Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One I know you get this a lot, but what's an unholy fairy like you doing in a mosque like this?
