Updated sample code output

A bit of cleanup and commentary, also switched to using $input as the
variable name, since this is what the regex tester uses internally.
master
Hauke D 7 years ago
parent 2af9b770d1
commit fcf045750d

@ -397,30 +397,34 @@ sub actual_update {
__SAMPLES__ __SAMPLES__
); );
for my $sample (@samples) { for my $input (@samples) {
print "### Sample: \"$sample\"\n"; print '### Sample: "', $input, '"', "\n";
ENDCODE ENDCODE
$sampcode =~ s{__SAMPLES__}{ join ",\n", map {" ".pp($_)} @samps }e; $sampcode =~ s{__SAMPLES__}{ join ",\n", map {" ".pp($_)} @samps }e;
$sampcode .= $precode=~s/^/ /mgr if length $precode; $sampcode .= $precode=~s/^/ /mgr if length $precode;
if ($flags=~/g/) { if ($flags=~/g/) {
$sampcode .= <<~'ENDCODE'; $sampcode .= <<~'ENDCODE';
while ( $sample =~ __REGEX__ ) { while ( $input =~ __REGEX__ ) {
print "Match! \"$&\"\n"; __BODY__
# can use $1, $2, etc. here
} }
ENDCODE ENDCODE
} }
else { else {
$sampcode .= <<~'ENDCODE'; $sampcode .= <<~'ENDCODE';
if ( $sample =~ __REGEX__ ) { if ( $input =~ __REGEX__ ) {
print "Match! \"$&\"\n"; __BODY__
# can use $1, $2, etc. here
} }
else { else {
print "No match!\n"; print "No match!\n";
} }
ENDCODE ENDCODE
} }
chomp( my $matchbody = <<~'ENDCODE' );
print 'Match! "', $&, '"', "\n";
# (Note: $& has performance penalty on Perl <5.20)
# You can use $1, $2, etc. here.
ENDCODE
$sampcode =~ s/__BODY__/$matchbody/;
my $re = $regex_str; my $re = $regex_str;
if ( $re=~/\n/ && $flags=~/x/ ) { if ( $re=~/\n/ && $flags=~/x/ ) {
$re =~ s/^/ /mg; $re =~ s/^/ /mg;

Loading…
Cancel
Save