astroboy has asked for the wisdom of the Perl Monks concerning the following question:
which outputs:use strict; use Regexp::Common qw /comment/; my @tests = ( { language => 'PL/SQL', description => 'PL/SQL Comment in String', code => q{ declare j varchar2(2); begin j := '--'; end; } }, { language => 'PL/SQL', description => 'PL/SQL no comment', code => q{ declare j varchar2(2); begin j := 'xx'; end; } }, { language => 'SQL', description => 'SQL Comment in String', code => q{ select '--' from dual; } }, { language => 'SQL', description => 'SQL no comment', code => q{ select 'xx' from dual; } }, { language => 'Perl', description => 'Perl Comment in String', code => q{ my $j = '#'; } }, { language => 'Perl', description => 'Perl no comment', code => q{ my $j = 'xx'; } } ); foreach my $test (@tests) { print $test->{description}."\n"; if ($RE{comment}{$test->{language}}->matches($test->{code})) { print "\tcontains comment\n"; } else { print "\tno comment\n"; } }
PL/SQL Comment in String contains comment PL/SQL no comment no comment SQL Comment in String contains comment SQL no comment no comment Perl Comment in String contains comment Perl no comment no comment
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comments detected in strings (|)
by tye (Sage) on Oct 20, 2014 at 21:54 UTC | |
by astroboy (Chaplain) on Oct 21, 2014 at 00:41 UTC | |
by Anonymous Monk on Oct 21, 2014 at 02:36 UTC |