Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

regex bug?

by I0 (Priest)
on Mar 14, 2002 at 01:27 UTC ( #151571=perlquestion: print w/ replies, xml ) Need Help??
I0 has asked for the wisdom of the Perl Monks concerning the following question:

#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 <>>>> #

Comment on regex bug?
Download Code
Re: regex bug?
by busunsl (Vicar) on Mar 14, 2002 at 07:45 UTC
    core dump on Perl 5.6.1 (626) win32
    no core dump on Perl 5.6.0 Linux and returns not the expected
    no core dump on Perl 5.6.1 Solaris and returns not the expected
Re: regex bug?
by tfrayner (Curate) on Mar 14, 2002 at 13:03 UTC
    Hi,

    MacOSX upgraded to perl5.6.1 returns: Example 2: func MAIN returns <func A returns <func B returns <2>+C(D())>>
    SPARC linux running perl5.6.1 throws a segfault.
    i386 linux running 5.6.1 also throws a segfault :-(.

    HTH,

    Tim

    Update: If I use warnings in the above code the linux versions behave identically to the MacOSX version. Interestingly, invoking perl with the -w switch and without use warnings still gives a segfault.

    Curious...

    Update 2: The recently-released MacPerl 5.6.1 shows similar behaviour to the linuxes (linices?), crashing instead with the message:

    # panic: end_shift. File 'Untitled'; Line 15
    Where line 15 is the recursive s/blah/&doFunc($1,$2)/ge line. I assume perl is balking at this point due to some unintentional recursion (i.e., possibly infinite?) which is abolished by using /geo instead of /ge. Why on earth use warnings should prevent this I have no idea. Bizarre (I think).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://151571]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-10-23 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (123 votes), past polls