Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Parsing with perl - Regexes and beyond

by tybalt89 (Monsignor)
on Sep 20, 2016 at 22:33 UTC ( [id://1172254]=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing with perl - Regexes and beyond
in thread RFC: Parsing with perl - Regexes and beyond

I tried running this code. Sometimes it worked and sometimes it failed.

Unusual for perl...

Then I remembered that recently hashes were randomized = bingo!

The line

my $reOps = qr[@{[ join '|', map{ quotemeta } keys %ops ]}];

needs to be changed to

my $reOps = qr[@{[ join '|', map{ quotemeta } sort { length $b <=> length $a } keys %ops ]}];

to keep * from being matched before **

Replies are listed 'Best First'.
Re^3: Parsing with perl - Regexes and beyond
by BrowserUk (Patriarch) on Sep 20, 2016 at 23:30 UTC

    Your correction needs a small correction:) We need to do the sort by length after the quotemetaing:

    my $reOps = qr[@{[ join '|', sort { length $b <=> length $a } map{ quo +temeta } keys %ops ]}];

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Parsing with perl - Regexes and beyond
by Discipulus (Canon) on Sep 22, 2016 at 08:09 UTC
    are you finally got an account? i suspect (and wish) you are one of the quality AnonymousMonk used to lurk here around.

    Anyway welcome to the monastery tybalt89!

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Thank you!

      Your suspicion is correct, I have been lurking around. Most of my AnonymousMonk postings can be identified by the code block having the thread URL in a comment on the third line, like Re^2: Parsing with perl - Regexes and beyond in this thread.

Re^3: Parsing with perl - Regexes and beyond
by BrowserUk (Patriarch) on Sep 20, 2016 at 22:56 UTC

    Thanks for the heads up. I'll amend the post above with your fix just in case someone else comes looking.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-28 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found