Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

search hang trouble

by greatdane (Beadle)
on Sep 01, 2006 at 20:46 UTC ( #570826=perlquestion: print w/replies, xml ) Need Help??

greatdane has asked for the wisdom of the Perl Monks concerning the following question:

I must be doing something stupid...

Why would the following while loop hang if the search string is not found in $PS ? Thanks in advance!

while ($PS =~ m/\G.*?Startpoint:\s*(\S+).*?Endpoint:\s*(\S+).*?Path Gr +oup:\s*(\S+).*?slack\s*\(.*?\)\s*(\S+)/gcsm) { <whatever> }
Its something to do with the depth of my search. It only hangs because all of the way through "slack" is found but "slack" is not found. If I make "Path Group" not found, then it does not hang. Also, if I make "slack" found, then it does not hang.

Update: its not the while that is hanging. Its actually the search that is hanging. The program hangs even when I take the search out of the while expression.

Code tags added by GrandFather

Replies are listed 'Best First'.
Re: search hang trouble
by greatdane (Beadle) on Sep 01, 2006 at 22:56 UTC
    I am now believing that the search is not hung but massively busy because of the cascaded non-greedy search pattern. The search hits on the first 3 specific strings but fails on the 4th specific string parsing a file with 50 cases of these failures. This results in a massive amount of nearly passing patterns.

    To solve my "seemingly hung" problem, I added a pre-check to the search string to see that the search is likely needed.

    Thanks for your help. This case can be considered closed.

Re: search hang trouble
by GrandFather (Saint) on Sep 01, 2006 at 21:10 UTC

    How about giving us a sample string that causes the match to "hang"?

    DWIM is Perl's answer to Gödel
Re: search hang trouble
by mreece (Friar) on Sep 01, 2006 at 21:21 UTC
    what does the /c do in /gcsm?
      search options:
      c Do not reset search pos on a failed match when /g is in effect. g Match globally, i.e., find all occurrences. i Do case-insensitive pattern matching. m Treat string as multiple lines. o Compile pattern only once. s Treat string as single line. x Use extended regular expressions.
      ah, i found it buried in perldoc perlretut:
      If you don't want the position reset after failure to match, add the "//c", as in "/regexp/gc".
      odd that it does not appear to be mentioned in perldoc perlre..
        Because it's not a regex flag, per se. It's a pattern matching operator flag. perlre only covers /i, /m, /s, and /x.

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://570826]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2022-12-04 06:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found