#Answering
How to find matching pairs ran into what appears to be a regexp bug
#Changing /geo to /ge Caused a core dump with v5.6.0
#but I couldn't replicate the core dump on v5.6.1 for IP32-irix
#v5.6.1 still has a problem though,
# C(D()) is not not expanded in this example
# Could someone verify this bug on their version of perl?
#
use strict;
# example 2
my $text = doFunc( "MAIN", "A(B(2)+C(D()))" );
print "Example 2: $text\n";
sub doFunc
{
my( $theFunc, $theParam ,$re) = @_;
{no warnings "uninitialized";
($re=$theParam)=~s/((\()|(\))|.)/${[')']}[!$3]\Q$1\E${['(']}[!$2]/g
+s;
}
$re= join'|',map{quotemeta}eval{$theParam=~/$re/};
die $@ if $@=~/unmatched/;
#$re = qr/$re/;
print "$theFunc: '$theParam' =~ /$re/\n";
print join"\n",$theParam=~/([A-Z]+)\(($re)\)/g,"\n";
$theParam =~ s/([A-Z]+)\(($re)\)/&doFunc($1,$2)/ge;
return "func $theFunc returns <$theParam>";
}
#returns
#Example 2: func MAIN returns <func A returns <func B returns <2>+C(D(
+))>>
#should return
#Example 2: func MAIN returns <func A returns <func B returns <2>+func
+ C ret\urns <func D returns <>>>>
#
In reply to regex bug?
by I0
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.