Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: regexp causes segfault

by shirkdog_perl (Beadle)
on Mar 06, 2003 at 01:30 UTC ( #240777=note: print w/replies, xml ) Need Help??


in reply to Re: regexp causes segfault
in thread regexp causes segfault

That was me, forgot I was not logged in:-)

Replies are listed 'Best First'.
Re: Re: Re: regexp causes segfault
by tachyon (Chancellor) on Mar 06, 2003 at 03:35 UTC

    I have no idea what you mean. All this regex does is walk the string (char by char) with a 1 char buffer (the last char). When it gets a match (last char not \\ and char eq ') it gets a match and we record the position. This is hardly a regex at all!

    Here it is completely C-ified - no regexes in sight. Possibly faster than the original post to boot but I can't be bothered to test.

    $str = " '==\\'==' '==5==' '\\'\\'' '\\'3' '\\'' '1' '' "; my $pos = 0; my $len = length $str; my $last = ''; my $char; while ( $pos < $len ) { $char = substr $str, $pos, 1; push @pos, $pos if $char eq "'" and $last ne "\\"; $pos++; $last = $char; } for ( my $i= 0; $i <@pos; $i +=2 ) { my $begin = $pos[$i]+1; my $end = $pos[$i+1]; my $str = substr $str, $begin, ($end -$begin); print "$begin $end |$str|\n"; }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://240777]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2023-02-05 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?