Click to See Complete Forum and Search --> : bored, here's a perl comment stripper...


YaRness
04-27-2001, 11:13 AM
...written in perl of course. also strips blank lines. basically, it prints only lines of code and no comments or empties.

"./foo.pl < input > output"


use strict;
use warnings;
my $inequalc=0;
while (<> )
{
if ($inequalc)
{
/^\=cut/ and ($inequalc = 0)
}
else
{
/^\=[a-zA-Z0-9]+/ and ($inequalc = 1)
or /^\s*(?:\#.*)?$/
or print;
}
}

was trying to obfuscate it, but i kept running into logical problems. merf.

YaRness
04-27-2001, 11:24 AM
($c&&(/^\=cut/&&($c=0)||1)||(/^\=[a-zA-Z0-9]+/&&($c = 1)||/^\s*(?:\#.*)?$/||print)) while (<> );

bah. forgot about the __END__ marker. oh well.

[ 27 April 2001: Message edited by: YaRness ]